Kernel based checkpoint/restart [v18]
Subsystems (59)
Re: [PATCH v18 49/80] c/r: support for UTS namespace
In reply to a message not in the archiveQuoted 13 lines · Nikita V. Youshchenko
Quoted 13 lines
checkpoint/namespace.c new file +12
-0+static struct uts_namespace *do_restore_uts_ns (struct ckpt_ctx *ctx) +#ifdef CONFIG_UTS_NS + uts_ns =create_uts_ns (); +if (!uts_ns) { + uts_ns =ERR_PTR (-ENOMEM ); + goto out; + } +down_read (&uts_sem); + name = &uts_ns->name; +memcpy (name->sysname, h->sysname,sizeof (name->sysname)); +memcpy (name->nodename, h->nodename,sizeof (name->nodename)); +memcpy (name->release, h->release,sizeof (name->release));
Quoted 8 lines
checkpoint/namespace.c line 80
Quoted 4 lines
checkpoint/namespace.c new file +4
-0+memcpy (name->version, h->version,sizeof (name->version)); +memcpy (name->machine, h->machine,sizeof (name->machine)); +memcpy (name->domainname, h->domainname,sizeof (name->domainname)); +up_read (&uts_sem);Could you please explain what for is this
down_read()/up_read()? You operate only on local objects: 'name' points to just-createduts_ns, 'h' is also local data.
Yup, good point, that looks unnecessary.
thanks,
-serge
Re: [PATCH v18 49/80] c/r: support for UTS namespace
In reply to a message not in the archiveQuoted 13 lines · Nikita V. Youshchenko
Quoted 13 lines
checkpoint/namespace.c new file +12
-0+static struct uts_namespace *do_restore_uts_ns (struct ckpt_ctx *ctx) +#ifdef CONFIG_UTS_NS + uts_ns =create_uts_ns (); +if (!uts_ns) { + uts_ns =ERR_PTR (-ENOMEM ); + goto out; + } +down_read (&uts_sem); + name = &uts_ns->name; +memcpy (name->sysname, h->sysname,sizeof (name->sysname)); +memcpy (name->nodename, h->nodename,sizeof (name->nodename)); +memcpy (name->release, h->release,sizeof (name->release));
Quoted 8 lines
checkpoint/namespace.c line 80
Quoted 4 lines
checkpoint/namespace.c new file +4
-0+memcpy (name->version, h->version,sizeof (name->version)); +memcpy (name->machine, h->machine,sizeof (name->machine)); +memcpy (name->domainname, h->domainname,sizeof (name->domainname)); +up_read (&uts_sem);Could you please explain what for is this
down_read()/up_read()? You operate only on local objects: 'name' points to just-createduts_ns, 'h' is also local data.
Nothing more than symmetry with checkpoint code, and a pedagogical aspect...
Can be replaced by a suitable comment.
Oren.
Re: [PATCH v18 49/80] c/r: support for UTS namespace
In reply to Nikita V. YoushchenkoQuoted 13 lines · Nikita V. Youshchenko
Quoted 13 lines
checkpoint/namespace.c new file +12
-0+static struct uts_namespace *do_restore_uts_ns (struct ckpt_ctx *ctx) +#ifdef CONFIG_UTS_NS + uts_ns =create_uts_ns (); +if (!uts_ns) { + uts_ns =ERR_PTR (-ENOMEM ); + goto out; + } +down_read (&uts_sem); + name = &uts_ns->name; +memcpy (name->sysname, h->sysname,sizeof (name->sysname)); +memcpy (name->nodename, h->nodename,sizeof (name->nodename)); +memcpy (name->release, h->release,sizeof (name->release));
Quoted 8 lines
checkpoint/namespace.c line 80
Quoted 4 lines
checkpoint/namespace.c new file +4
-0+memcpy (name->version, h->version,sizeof (name->version)); +memcpy (name->machine, h->machine,sizeof (name->machine)); +memcpy (name->domainname, h->domainname,sizeof (name->domainname)); +up_read (&uts_sem);Could you please explain what for is this
down_read()/up_read()? You operate only on local objects: 'name' points to just-createduts_ns, 'h' is also local data.
Nothing more than symmetry with checkpoint code, and a pedagogical aspect...
Can be replaced by a suitable comment.
Oren.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
A message that is not in the archive (sent off-list or not yet received): 1253749920-18673-50-git-send-email-orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org
Re: [PATCH v18 49/80] c/r: support for UTS namespace
Quoted 7 lines
checkpoint/namespace.c new file +6
-0+static struct uts_namespace *do_restore_uts_ns (struct ckpt_ctx *ctx) +#ifdef CONFIG_UTS_NS + uts_ns =create_uts_ns (); +if (!uts_ns) { + uts_ns =ERR_PTR (-ENOMEM ); + goto out;
checkpoint/namespace.c line 80
Quoted 10 lines
checkpoint/namespace.c new file +10
-0+ } +down_read (&uts_sem); + name = &uts_ns->name; +memcpy (name->sysname, h->sysname,sizeof (name->sysname)); +memcpy (name->nodename, h->nodename,sizeof (name->nodename)); +memcpy (name->release, h->release,sizeof (name->release)); +memcpy (name->version, h->version,sizeof (name->version)); +memcpy (name->machine, h->machine,sizeof (name->machine)); +memcpy (name->domainname, h->domainname,sizeof (name->domainname)); +up_read (&uts_sem);
Could you please explain what for is this down_read() / up_read() ? You operate only on local objects: 'name' points to just-created uts_ns, 'h' is also local data.
PATCH v18 50/80 c/r (ipc): allow allocation of a desired ipc identifier
In reply to Oren LaadanDuring restart, we need to allocate ipc objects that with the same identifiers as recorded during checkpoint. Modify the allocation code allow an in-kernel caller to request a specific ipc identifier. The system call interface remains unchanged.
--- ipc/msg.c | 17 ++++++++++++----- ipc/sem.c | 17 ++++++++++++----- ipc/shm.c | 19 +++++++++++++------ ipc/util.c | 42 +++++++++++++++++++++++++++++------------- ipc/util.h | 9 +++++---- 5 files changed, 71 insertions(+), 33 deletions(-)
ipc/msg.c +12 -5
@@ -73,7 +73,7 @@ struct msg_sender {#define msg_unlock (msq) ipc_unlock(&(msq)->q_perm)static void freeque (struct ipc_namespace *,struct kern_ipc_perm *); -static int newque (struct ipc_namespace *,struct ipc_params *); +static int newque (struct ipc_namespace *,struct ipc_params *,int );#ifdef CONFIG_PROC_FS static int sysvipc_msg_proc_show (struct seq_file *s,void *it);#endif
@@ -174,10 +174,12 @@ static inline void msg_rmid(struct ipc_namespace *ns, struct msg_queue *s)* newque - Create a new msg queue * @ns: namespace * @params: ptr to the structure that contains the key and msgflg +* @req_id: request desired id if available (-1 if don't care) * * Called with msg_ids.rw_mutex held (writer) */ -static int newque (struct ipc_namespace *ns,struct ipc_params *params) +static int +newque (struct ipc_namespace *ns,struct ipc_params *params,int req_id) {struct msg_queue *msq;int id, retval;
@@ -201,7 +203,7 @@ static int newque(struct ipc_namespace *ns, struct ipc_params *params)/* * ipc_addid() locks msq */ - id =ipc_addid (&msg_ids (ns), &msq->q_perm, ns->msg_ctlmni); + id =ipc_addid (&msg_ids (ns), &msq->q_perm, ns->msg_ctlmni, req_id);if (id <0 ) {security_msg_queue_free (msq);ipc_rcu_putref (msq);
@@ -309,7 +311,7 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)return security_msg_queue_associate (msq, msgflg); } -SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg) +int do_msgget (key_t key,int msgflg,int req_id) {struct ipc_namespace *ns;struct ipc_ops msg_ops;
@@ -324,7 +326,12 @@ SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg) msg_params.key = key; msg_params.flg = msgflg; -return ipcget (ns, &msg_ids (ns), &msg_ops, &msg_params); +return ipcget (ns, &msg_ids (ns), &msg_ops, &msg_params, req_id); +} + +SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg) +{ +return do_msgget (key, msgflg,-1 ); } static inline unsigned long
ipc/sem.c +12 -5
@@ -92,7 +92,7 @@#define sem_unlock (sma) ipc_unlock(&(sma)->sem_perm)#define sem_checkid (sma, semid) ipc_checkid(&sma->sem_perm, semid) -static int newary (struct ipc_namespace *,struct ipc_params *); +static int newary (struct ipc_namespace *,struct ipc_params *,int );static void freeary (struct ipc_namespace *,struct kern_ipc_perm *);#ifdef CONFIG_PROC_FS static int sysvipc_sem_proc_show (struct seq_file *s,void *it);
@@ -227,11 +227,13 @@ static inline void sem_rmid(struct ipc_namespace *ns, struct sem_array *s)* newary - Create a new semaphore set * @ns: namespace * @params: ptr to the structure that contains key, semflg and nsems +* @req_id: request desired id if available (-1 if don't care) * * Called with sem_ids.rw_mutex held (as a writer) */ -static int newary (struct ipc_namespace *ns,struct ipc_params *params) +static int +newary (struct ipc_namespace *ns,struct ipc_params *params,int req_id) {int id;int retval;
@@ -263,7 +265,7 @@ static int newary(struct ipc_namespace *ns, struct ipc_params *params)return retval; } - id =ipc_addid (&sem_ids (ns), &sma->sem_perm, ns->sc_semmni); + id =ipc_addid (&sem_ids (ns), &sma->sem_perm, ns->sc_semmni, req_id);if (id <0 ) {security_sem_free (sma);ipc_rcu_putref (sma);
@@ -308,7 +310,7 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,return 0 ; } -SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg) +int do_semget (key_t key,int nsems,int semflg,int req_id) {struct ipc_namespace *ns;struct ipc_ops sem_ops;
@@ -327,7 +329,12 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg) sem_params.flg = semflg; sem_params.u.nsems = nsems; -return ipcget (ns, &sem_ids (ns), &sem_ops, &sem_params); +return ipcget (ns, &sem_ids (ns), &sem_ops, &sem_params, req_id); +} + +SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg) +{ +return do_semget (key, nsems, semflg,-1 ); }/*
ipc/shm.c +13 -6
@@ -62,7 +62,7 @@ static struct vm_operations_struct shm_vm_ops;#define shm_unlock (shp) \ ipc_unlock(&(shp)->shm_perm) -static int newseg (struct ipc_namespace *,struct ipc_params *); +static int newseg (struct ipc_namespace *,struct ipc_params *,int );static void shm_open (struct vm_area_struct *vma);static void shm_close (struct vm_area_struct *vma);static void shm_destroy (struct ipc_namespace *ns,struct shmid_kernel *shp);
@@ -83,7 +83,7 @@ void shm_init_ns(struct ipc_namespace *ns)* Called with shm_ids.rw_mutex (writer) and the shp structure locked. * Only shm_ids.rw_mutex remains locked on exit. */ -static void do_shm_rmid (struct ipc_namespace *ns,struct kern_ipc_perm *ipcp) +void do_shm_rmid (struct ipc_namespace *ns,struct kern_ipc_perm *ipcp) {struct shmid_kernel *shp; shp = container_of(ipcp, struct shmid_kernel, shm_perm);
@@ -326,11 +326,13 @@ static struct vm_operations_struct shm_vm_ops = {* newseg - Create a new shared memory segment * @ns: namespace * @params: ptr to the structure that contains key, size and shmflg +* @req_id: request desired id if available (-1 if don't care) * * Called with shm_ids.rw_mutex held as a writer. */ -static int newseg (struct ipc_namespace *ns,struct ipc_params *params) +static int +newseg (struct ipc_namespace *ns,struct ipc_params *params,int req_id) {key_t key = params->key;int shmflg = params->flg;
@@ -385,7 +387,7 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)if (IS_ERR (file)) goto no_file; - id =ipc_addid (&shm_ids (ns), &shp->shm_perm, ns->shm_ctlmni); + id =ipc_addid (&shm_ids (ns), &shp->shm_perm, ns->shm_ctlmni, req_id);if (id <0 ) { error = id; goto no_id;
@@ -445,7 +447,7 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,return 0 ; } -SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg) +int do_shmget (key_t key,size_t size,int shmflg,int req_id) {struct ipc_namespace *ns;struct ipc_ops shm_ops;
@@ -461,7 +463,12 @@ SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg) shm_params.flg = shmflg; shm_params.u.size = size; -return ipcget (ns, &shm_ids (ns), &shm_ops, &shm_params); +return ipcget (ns, &shm_ids (ns), &shm_ops, &shm_params, req_id); +} + +SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg) +{ +return do_shmget (key, size, shmflg,-1 ); }static inline unsigned long copy_shmid_to_user (void __user *buf,struct shmid64_ds *in,int version)
ipc/util.c +29 -13
113 lines not on this page · raw message
ipc/util.h +5 -4
@@ -71,7 +71,7 @@ struct ipc_params {* . routine to call for an extra check if needed */ struct ipc_ops { -int (*getnew) (struct ipc_namespace *,struct ipc_params *); +int (*getnew) (struct ipc_namespace *,struct ipc_params *,int );int (*associate) (struct kern_ipc_perm *,int );int (*more_checks) (struct kern_ipc_perm *,struct ipc_params *); };
@@ -94,7 +94,7 @@ void __init ipc_init_proc_interface(const char *path, const char *header,#define ipcid_to_idx (id) ((id) % SEQ_MULTIPLIER)/* must be called with ids->rw_mutex acquired for writing */ -int ipc_addid (struct ipc_ids *,struct kern_ipc_perm *,int ); +int ipc_addid (struct ipc_ids *,struct kern_ipc_perm *,int ,int );/* must be called with ids->rw_mutex acquired for reading */ int ipc_get_maxid (struct ipc_ids *);
@@ -171,7 +171,8 @@ static inline void ipc_unlock(struct kern_ipc_perm *perm)struct kern_ipc_perm *ipc_lock_check (struct ipc_ids *ids,int id);int ipcget (struct ipc_namespace *ns,struct ipc_ids *ids, -struct ipc_ops *ops,struct ipc_params *params); +struct ipc_ops *ops,struct ipc_params *params,int req_id);void free_ipcs (struct ipc_namespace *ns,struct ipc_ids *ids, -void (*free)(struct ipc_namespace *,struct kern_ipc_perm *)); +void (*free)(struct ipc_namespace *,struct kern_ipc_perm *)); +#endif
Signature · 7 lines
1.6.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v18 51/80 c/r: save and restore sysvipc namespace basics
In reply to Oren LaadanAdd the helpers to checkpoint and restore the contents of 'struct kern_ipc_perm'. Add header structures for ipc state. Put place-holders to save and restore ipc state.
Save and restores the common state (parameters) of ipc namespace.
Generic code to iterate through the objects of sysvipc shared memory, message queues and semaphores. The logic to save and restore the state of these objects will be added in the next few patches.
Right now, we return -EPERM if the user calling sys_restart() isn't allowed to create an object with the checkpointed uid. We may prefer to simply use the caller's uid in that case - but that could lead to subtle userspace bugs? Unsure, so going for the stricter behavior.
TODO: restore kern_ipc_perms->security.
Changelog[v17]:
- Fix include: use checkpoint.h not checkpoint_hdr.h
- Collect nsproxy->ipc_ns
- Restore objects in the right namespace
- If !CONFIG_IPC_NS only restore objects, not global settings
- Don't overwrite global ipc-ns if !CONFIG_IPC_NS
- Reset the checkpointed uid and gid info on ipc objects
- Fix compilation with CONFIG_SYSVIPC=n
Changelog [Dan Smith <[email protected]>]
- Fix compilation with CONFIG_SYSVIPC=n
- Update to match UTS changes
--- checkpoint/checkpoint.c | 2 - checkpoint/objhash.c | 28 ++++ include/linux/checkpoint.h | 13 ++ include/linux/checkpoint_hdr.h | 54 +++++++ include/linux/checkpoint_types.h | 1 + init/Kconfig | 6 + ipc/Makefile | 2 +- ipc/checkpoint.c | 317 ++++++++++++++++++++++++++++++++++++++ ipc/namespace.c | 2 +- ipc/util.h | 10 ++ kernel/nsproxy.c | 22 ++- 11 files changed, 449 insertions(+), 8 deletions(-) create mode 100644 ipc/checkpoint.c
checkpoint/checkpoint.c +0 -2
@@ -424,8 +424,6 @@ static int may_checkpoint_task(struct ckpt_ctx *ctx, struct task_struct *t)rcu_read_lock (); nsproxy =task_nsproxy (t); -if (nsproxy->ipc_ns != ctx->root_nsproxy->ipc_ns) - ret = -EPERM ;if (nsproxy->mnt_ns != ctx->root_nsproxy->mnt_ns) {__ckpt_write_err (ctx,"TE" ,"bad mnt_ns" , -EPERM ); ret = -EPERM ;
checkpoint/objhash.c +28 -0
@@ -15,6 +15,8 @@#include <linux/hash.h> #include <linux/file.h> #include <linux/fdtable.h> +#include <linux/sched.h> +#include <linux/ipc_namespace.h> #include <linux/checkpoint.h> #include <linux/checkpoint_hdr.h>
@@ -154,6 +156,22 @@ static int obj_uts_ns_users(void *ptr)return atomic_read (&((struct uts_namespace *) ptr)->kref.refcount); } +static int obj_ipc_ns_grab (void *ptr) +{ +get_ipc_ns ((struct ipc_namespace *) ptr); +return 0 ; +} + +static void obj_ipc_ns_drop (void *ptr,int lastref) +{ +put_ipc_ns ((struct ipc_namespace *) ptr); +} + +static int obj_ipc_ns_users (void *ptr) +{ +return atomic_read (&((struct ipc_namespace *) ptr)->count); +} +static struct ckpt_obj_ops ckpt_obj_ops[] = {/* ignored object */ {
@@ -219,6 +237,16 @@ static struct ckpt_obj_ops ckpt_obj_ops[] = { .checkpoint = checkpoint_uts_ns, .restore = restore_uts_ns, }, +/* ipc_ns object */ + { + .obj_name = "IPC_NS", + .obj_type = CKPT_OBJ_IPC_NS, + .ref_drop = obj_ipc_ns_drop, + .ref_grab = obj_ipc_ns_grab, + .ref_users = obj_ipc_ns_users, + .checkpoint = checkpoint_ipc_ns, + .restore = restore_ipc_ns, + }, };
include/linux/checkpoint.h +13 -0
@@ -22,6 +22,9 @@#ifdef __KERNEL__#ifdef CONFIG_CHECKPOINT +#include <linux/sched.h> +#include <linux/nsproxy.h> +#include <linux/ipc_namespace.h> #include <linux/checkpoint_types.h> #include <linux/checkpoint_hdr.h> #include <linux/err.h>
@@ -151,6 +154,15 @@ extern void *restore_ns(struct ckpt_ctx *ctx);extern int checkpoint_uts_ns (struct ckpt_ctx *ctx,void *ptr);extern void *restore_uts_ns (struct ckpt_ctx *ctx); +/* ipc-ns */ +#ifdef CONFIG_SYSVIPC +extern int checkpoint_ipc_ns (struct ckpt_ctx *ctx,void *ptr); +extern void *restore_ipc_ns (struct ckpt_ctx *ctx); +#else +#define checkpoint_ipc_ns checkpoint_bad +#define restore_ipc_ns restore_bad +#endif /* CONFIG_SYSVIPC */ +/* file table */ extern int ckpt_collect_file_table (struct ckpt_ctx *ctx,struct task_struct *t); extern int checkpoint_obj_file_table(struct ckpt_ctx *ctx,
@@ -224,6 +236,7 @@ static inline int ckpt_validate_errno(int errno)#define CKPT_DFILE 0x10/* files and filesystem */ #define CKPT_DMEM 0x20/* memory state */ #define CKPT_DPAGE 0x40/* memory pages */ +#define CKPT_DIPC 0x80/* sysvipc */ #define CKPT_DDEFAULT 0xffff/* default debug level */
include/linux/checkpoint_hdr.h +54 -0
82 lines not on this page · raw message
include/linux/checkpoint_types.h +1 -0
@@ -24,6 +24,7 @@struct ckpt_stats {int uts_ns; +int ipc_ns; };struct ckpt_ctx {
init/Kconfig +6 -0
@@ -191,6 +191,12 @@ config SYSVIPC section 6.4 of the Linux Programmer's Guide, available from <http://www.tldp.org/guides.html>. +config SYSVIPC_CHECKPOINT + bool + depends on SYSVIPC + depends on CHECKPOINT + default y + config SYSVIPC_SYSCTL bool depends on SYSVIPC
ipc/Makefile +1 -1
@@ -9,4 +9,4 @@ obj_mq-$(CONFIG_COMPAT) += compat_mq.o obj-$(CONFIG_POSIX_MQUEUE) += mqueue.o msgutil.o $(obj_mq-y) obj-$(CONFIG_IPC_NS) += namespace.o obj-$(CONFIG_POSIX_MQUEUE_SYSCTL) += mq_sysctl.o - +obj-$(CONFIG_SYSVIPC_CHECKPOINT) += checkpoint.o
ipc/checkpoint.c new file +317 -0
317 lines not on this page · raw message
ipc/namespace.c +1 -1
@@ -14,7 +14,7 @@#include "util.h" -static struct ipc_namespace *create_ipc_ns (void ) +struct ipc_namespace *create_ipc_ns (void ) {struct ipc_namespace *ns;int err;
ipc/util.h +10 -0
@@ -12,6 +12,7 @@#include <linux/unistd.h> #include <linux/err.h> +#include <linux/checkpoint.h> #define SEQ_MULTIPLIER (IPCMNI)
@@ -175,4 +176,13 @@ int ipcget(struct ipc_namespace *ns, struct ipc_ids *ids,void free_ipcs (struct ipc_namespace *ns,struct ipc_ids *ids,void (*free)(struct ipc_namespace *,struct kern_ipc_perm *)); +struct ipc_namespace *create_ipc_ns (void ); + +#ifdef CONFIG_CHECKPOINT +extern int checkpoint_fill_ipc_perms (struct ckpt_hdr_ipc_perms *h, +struct kern_ipc_perm *perm); +extern int restore_load_ipc_perms (struct ckpt_hdr_ipc_perms *h, +struct kern_ipc_perm *perm); +#endif +#endif
kernel/nsproxy.c +18 -4
@@ -248,6 +248,7 @@ int ckpt_collect_ns(struct ckpt_ctx *ctx, struct task_struct *t) ret =ckpt_obj_collect (ctx, nsproxy->uts_ns,CKPT_OBJ_UTS_NS );if (ret <0 ) goto out; + ret =ckpt_obj_collect (ctx, nsproxy->ipc_ns,CKPT_OBJ_IPC_NS );/* TODO: collect other namespaces here */ out:
@@ -268,6 +269,11 @@ static int do_checkpoint_ns(struct ckpt_ctx *ctx, struct nsproxy *nsproxy)if (ret <=0 ) goto out; h->uts_objref = ret; + ret =checkpoint_obj (ctx, nsproxy->ipc_ns,CKPT_OBJ_IPC_NS ); +if (ret <0 ) + goto out; + h->ipc_objref = ret; +/* TODO: Write other namespaces here */ ret =ckpt_write_obj (ctx, &h->h);
@@ -287,6 +293,7 @@ static struct nsproxy *do_restore_ns(struct ckpt_ctx *ctx)struct ckpt_hdr_ns *h;struct nsproxy *nsproxy =NULL ;struct uts_namespace *uts_ns; +struct ipc_namespace *ipc_ns;int ret; h =ckpt_read_obj_type (ctx,sizeof (*h),CKPT_HDR_NS );
@@ -294,7 +301,8 @@ static struct nsproxy *do_restore_ns(struct ckpt_ctx *ctx)return (struct nsproxy *) h; ret = -EINVAL ; -if (h->uts_objref <=0 ) +if (h->uts_objref <=0 || + h->ipc_objref <=0 ) goto out; uts_ns =ckpt_obj_fetch (ctx, h->uts_objref,CKPT_OBJ_UTS_NS );
@@ -302,8 +310,13 @@ static struct nsproxy *do_restore_ns(struct ckpt_ctx *ctx) ret =PTR_ERR (uts_ns); goto out; } + ipc_ns =ckpt_obj_fetch (ctx, h->ipc_objref,CKPT_OBJ_IPC_NS ); +if (IS_ERR (ipc_ns)) { + ret =PTR_ERR (ipc_ns); + goto out; + } -#if defined(COFNIG_UTS_NS ) +#if defined(COFNIG_UTS_NS ) || defined(CONFIG_IPC_NS ) ret = -ENOMEM ; nsproxy =create_nsproxy ();if (!nsproxy)
@@ -311,9 +324,9 @@ static struct nsproxy *do_restore_ns(struct ckpt_ctx *ctx)get_uts_ns (uts_ns); nsproxy->uts_ns = uts_ns; - -get_ipc_ns (current->nsproxy->ipc_ns); +get_ipc_ns (ipc_ns); nsproxy->ipc_ns = ipc_ns; +get_pid_ns (current->nsproxy->pid_ns); nsproxy->pid_ns = current->nsproxy->pid_ns;get_mnt_ns (current->nsproxy->mnt_ns);
@@ -325,6 +338,7 @@ static struct nsproxy *do_restore_ns(struct ckpt_ctx *ctx)get_nsproxy (nsproxy);BUG_ON (nsproxy->uts_ns != uts_ns); +BUG_ON (nsproxy->ipc_ns != ipc_ns);#endif /* TODO: add more namespaces here */
Signature · 7 lines
1.6.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v18 52/80 c/r: support share-memory sysv-ipc
In reply to Oren LaadanCheckpoint of sysvipc shared memory is performed in two steps: first, the entire ipc namespace is dumped as a whole by iterating through all shm objects and dumping the contents of each one. The shmem inode is registered in the objhash. Second, for each vma that refers to ipc shared memory we find the inode in the objhash, and save the objref.
(If we find a new inode, that indicates that the ipc namespace is not entirely frozen and someone must have manipulated it since step 1).
Handling of shm objects that have been deleted (via IPC_RMID) is left to a later patch in this series.
Changelog[v18]:
- Collect files used by shm objects
- Use file instead of inode as shared object during checkpoint
Changelog[v17]:
- Restore objects in the right namespace
- Properly initialize ctx->deferqueue
- Fix compilation with CONFIG_CHECKPOINT=n
--- checkpoint/checkpoint.c | 5 + checkpoint/memory.c | 28 ++++- checkpoint/restart.c | 5 + checkpoint/sys.c | 7 + include/linux/checkpoint.h | 10 ++ include/linux/checkpoint_hdr.h | 19 +++- include/linux/checkpoint_types.h | 1 + include/linux/shm.h | 15 ++ ipc/Makefile | 2 +- ipc/checkpoint.c | 25 +++- ipc/checkpoint_shm.c | 277 ++++++++++++++++++++++++++++++++++++++ ipc/shm.c | 84 +++++++++++- ipc/util.h | 9 ++ kernel/nsproxy.c | 8 + mm/shmem.c | 2 +- 15 files changed, 482 insertions(+), 15 deletions(-) create mode 100644 ipc/checkpoint_shm.c
checkpoint/checkpoint.c +5 -0
@@ -24,6 +24,7 @@#include <linux/utsname.h> #include <linux/magic.h> #include <linux/hrtimer.h> +#include <linux/deferqueue.h> #include <linux/checkpoint.h> #include <linux/checkpoint_hdr.h>
@@ -793,6 +794,10 @@ long do_checkpoint(struct ckpt_ctx *ctx, pid_t pid)if (ret <0 ) goto out; + ret =deferqueue_run (ctx->deferqueue);/* run deferred work */ +if (ret <0 ) + goto out; +/* verify that all objects were indeed visited */ if (!ckpt_obj_visited (ctx)) {ckpt_write_err (ctx,"E" ,"leak: unvisited" , -EBUSY );
checkpoint/memory.c +25 -3
@@ -20,6 +20,7 @@#include <linux/mman.h> #include <linux/pagemap.h> #include <linux/mm_types.h> +#include <linux/shm.h> #include <linux/proc_fs.h> #include <linux/swap.h> #include <linux/checkpoint.h>
@@ -459,9 +460,9 @@ static int vma_dump_pages(struct ckpt_ctx *ctx, int total)* virtual addresses into ctx->pgarr_list page-array chain. Then dump * the addresses, followed by the page contents. */ -static int checkpoint_memory_contents (struct ckpt_ctx *ctx, -struct vm_area_struct *vma, -struct inode *inode) +int checkpoint_memory_contents (struct ckpt_ctx *ctx, +struct vm_area_struct *vma, +struct inode *inode) {struct ckpt_hdr_pgarr *h;unsigned long addr, end;
@@ -1084,6 +1085,13 @@ static int anon_private_restore(struct ckpt_ctx *ctx,return private_vma_restore (ctx, mm,NULL , h); } +static int bad_vma_restore (struct ckpt_ctx *ctx, +struct mm_struct *mm, +struct ckpt_hdr_vma *h) +{ +return -EINVAL ; +} +/* callbacks to restore vma per its type: */ struct restore_vma_ops {char *vma_name;
@@ -1136,6 +1144,20 @@ static struct restore_vma_ops restore_vma_ops[] = { .vma_type = CKPT_VMA_SHM_FILE, .restore = filemap_restore, }, +/* sysvipc shared */ + { + .vma_name = "IPC SHARED", + .vma_type = CKPT_VMA_SHM_IPC, + /* ipc inode itself is restore by restore_ipc_ns()... */ + .restore = bad_vma_restore, + + }, +/* sysvipc shared (skip) */ + { + .vma_name = "IPC SHARED (skip)", + .vma_type = CKPT_VMA_SHM_IPC_SKIP, + .restore = ipcshm_restore, + }, };/**
checkpoint/restart.c +5 -0
@@ -21,6 +21,7 @@#include <linux/utsname.h> #include <asm/syscall.h> #include <linux/elf.h> +#include <linux/deferqueue.h> #include <linux/checkpoint.h> #include <linux/checkpoint_hdr.h>
@@ -881,6 +882,10 @@ static int do_restore_coord(struct ckpt_ctx *ctx, pid_t pid) goto out; } + ret =deferqueue_run (ctx->deferqueue);/* run deferred work */ +if (ret <0 ) + goto out; + ret =restore_read_tail (ctx);if (ret <0 ) goto out;
checkpoint/sys.c +7 -0
@@ -21,6 +21,7 @@#include <linux/uaccess.h> #include <linux/capability.h> #include <linux/checkpoint.h> +#include <linux/deferqueue.h> /* * ckpt_unpriv_allowed - sysctl controlled, do not allow checkpoints or
@@ -191,6 +192,9 @@ static void ckpt_ctx_free(struct ckpt_ctx *ctx) {BUG_ON (atomic_read (&ctx->refcount)); +if (ctx->deferqueue) +deferqueue_destroy (ctx->deferqueue); +if (ctx->files_deferq)deferqueue_destroy (ctx->files_deferq);
@@ -243,6 +247,9 @@ static struct ckpt_ctx *ckpt_ctx_alloc(int fd, unsigned long uflags, err = -ENOMEM ;if (ckpt_obj_hash_alloc (ctx) <0 ) goto err; + ctx->deferqueue =deferqueue_create (); +if (!ctx->deferqueue) + goto err; ctx->files_deferq =deferqueue_create ();if (!ctx->files_deferq)
include/linux/checkpoint.h +10 -0
@@ -158,9 +158,16 @@ extern void *restore_uts_ns(struct ckpt_ctx *ctx);#ifdef CONFIG_SYSVIPC extern int checkpoint_ipc_ns (struct ckpt_ctx *ctx,void *ptr);extern void *restore_ipc_ns (struct ckpt_ctx *ctx); +extern int ckpt_collect_ipc_ns (struct ckpt_ctx *ctx, +struct ipc_namespace *ipc_ns);#else #define checkpoint_ipc_ns checkpoint_bad#define restore_ipc_ns restore_bad +static inline int ckpt_collect_ipc_ns (struct ckpt_ctx *ctx, +struct ipc_namespace *ipc_ns) +{ +return 0 ; +}#endif /* CONFIG_SYSVIPC */ /* file table */
@@ -215,6 +222,9 @@ extern unsigned long generic_vma_restore(struct mm_struct *mm,extern int private_vma_restore (struct ckpt_ctx *ctx,struct mm_struct *mm,struct file *file,struct ckpt_hdr_vma *h); +extern int checkpoint_memory_contents (struct ckpt_ctx *ctx, +struct vm_area_struct *vma, +struct inode *inode);extern int restore_memory_contents (struct ckpt_ctx *ctx,struct inode *inode);
include/linux/checkpoint_hdr.h +18 -1
@@ -314,7 +314,9 @@ enum vma_type {CKPT_VMA_SHM_ANON ,/* shared anonymous */ CKPT_VMA_SHM_ANON_SKIP ,/* shared anonymous (skip contents) */ CKPT_VMA_SHM_FILE ,/* shared mapped file, only msync */ - CKPT_VMA_MAX +CKPT_VMA_SHM_IPC ,/* shared sysvipc */ +CKPT_VMA_SHM_IPC_SKIP ,/* shared sysvipc (skip contents) */ + CKPT_VMA_MAX, };/* vma descriptor */
@@ -364,6 +366,7 @@ struct ckpt_hdr_ipc { } __attribute__((aligned(8)));struct ckpt_hdr_ipc_perms { +struct ckpt_hdr h;__s32 id;__u32 key;__u32 uid;
@@ -375,6 +378,20 @@ struct ckpt_hdr_ipc_perms {__u64 seq; } __attribute__((aligned(8))); +struct ckpt_hdr_ipc_shm { +struct ckpt_hdr h; +struct ckpt_hdr_ipc_perms perms; +__u64 shm_segsz; +__u64 shm_atim; +__u64 shm_dtim; +__u64 shm_ctim; +__s32 shm_cprid; +__s32 shm_lprid; +__u32 mlock_uid; +__u32 flags; +__u32 objref; +} __attribute__((aligned (8 ))); +#define CKPT_TST_OVERFLOW_16 (a, b) \ ((sizeof(a) > sizeof(b)) && ((a) > SHORT_MAX))
include/linux/checkpoint_types.h +1 -0
@@ -48,6 +48,7 @@ struct ckpt_ctx {atomic_t refcount;struct ckpt_obj_hash *obj_hash;/* repository for shared objects */ +struct deferqueue_head *deferqueue;/* deferred c/r work */ struct deferqueue_head *files_deferq;/* deferred file-table work */ struct path fs_mnt;/* container root (FIXME) */
include/linux/shm.h +15 -0
@@ -118,6 +118,21 @@ static inline int is_file_shm_hugepages(struct file *file) }#endif +struct ipc_namespace ; +extern int shmctl_down (struct ipc_namespace *ns,int shmid,int cmd, +struct shmid_ds __user *buf,int version); + +#ifdef CONFIG_CHECKPOINT +#ifdef CONFIG_SYSVIPC +struct ckpt_ctx ; +struct ckpt_hdr_vma ; +extern int ipcshm_restore (struct ckpt_ctx *ctx,struct mm_struct *mm, +struct ckpt_hdr_vma *h); +#else +#define ipcshm_restore NULL +#endif +#endif +#endif /* __KERNEL__ */ #endif /* _LINUX_SHM_H_ */
ipc/Makefile +1 -1
@@ -9,4 +9,4 @@ obj_mq-$(CONFIG_COMPAT) += compat_mq.o obj-$(CONFIG_POSIX_MQUEUE) += mqueue.o msgutil.o $(obj_mq-y) obj-$(CONFIG_IPC_NS) += namespace.o obj-$(CONFIG_POSIX_MQUEUE_SYSCTL) += mq_sysctl.o -obj-$(CONFIG_SYSVIPC_CHECKPOINT) += checkpoint.o +obj-$(CONFIG_SYSVIPC_CHECKPOINT) += checkpoint.o checkpoint_shm.o
ipc/checkpoint.c +23 -2
@@ -113,9 +113,9 @@ static int do_checkpoint_ipc_ns(struct ckpt_ctx *ctx,if (ret <0 )return ret; -#if 0 /* NEXT FEW PATCHES */ ret =checkpoint_ipc_any (ctx, ipc_ns,IPC_SHM_IDS ,CKPT_HDR_IPC_SHM , checkpoint_ipc_shm); +#if 0 /* NEXT FEW PATCHES */ if (ret <0 )return ret; ret = checkpoint_ipc_any(ctx, ipc_ns, IPC_MSG_IDS,
@@ -134,6 +134,27 @@ int checkpoint_ipc_ns(struct ckpt_ctx *ctx, void *ptr) }/************************************************************************** +* Collect +*/ + +int ckpt_collect_ipc_ns (struct ckpt_ctx *ctx,struct ipc_namespace *ipc_ns) +{ +struct ipc_ids *ipc_ids; +int ret; + +/* +* Each shm object holds a reference to a file pointer, so +* collect them. Nothing to do for msg and sem. +*/ + ipc_ids = &ipc_ns->ids[IPC_SHM_IDS ]; +down_read (&ipc_ids->rw_mutex); + ret =idr_for_each (&ipc_ids->ipcs_idr, ckpt_collect_ipc_shm, ctx); +up_read (&ipc_ids->rw_mutex); + +return ret; +} + +/************************************************************************** * Restart */
@@ -286,9 +307,9 @@ static struct ipc_namespace *do_restore_ipc_ns(struct ckpt_ctx *ctx)get_ipc_ns (ipc_ns);#endif -#if 0 /* NEXT FEW PATCHES */ ret =restore_ipc_any (ctx, ipc_ns,IPC_SHM_IDS ,CKPT_HDR_IPC_SHM , restore_ipc_shm); +#if 0 /* NEXT FEW PATCHES */ if (ret <0 ) goto out; ret = restore_ipc_any(ctx, ipc_ns, IPC_MSG_IDS,
ipc/checkpoint_shm.c new file +277 -0
277 lines not on this page · raw message
ipc/shm.c +77 -7
124 lines not on this page · raw message
ipc/util.h +9 -0
@@ -178,11 +178,20 @@ void free_ipcs(struct ipc_namespace *ns, struct ipc_ids *ids,struct ipc_namespace *create_ipc_ns (void ); +int do_shmget (struct ipc_namespace *ns,key_t key,size_t size,int shmflg, +int req_id); +void do_shm_rmid (struct ipc_namespace *ns,struct kern_ipc_perm *ipcp); + +#ifdef CONFIG_CHECKPOINT extern int checkpoint_fill_ipc_perms (struct ckpt_hdr_ipc_perms *h,struct kern_ipc_perm *perm);extern int restore_load_ipc_perms (struct ckpt_hdr_ipc_perms *h,struct kern_ipc_perm *perm); + +extern int ckpt_collect_ipc_shm (int id,void *p,void *data); +extern int checkpoint_ipc_shm (int id,void *p,void *data); +extern int restore_ipc_shm (struct ckpt_ctx *ctx,struct ipc_namespace *ns);#endif #endif
kernel/nsproxy.c +8 -0
@@ -249,6 +249,14 @@ int ckpt_collect_ns(struct ckpt_ctx *ctx, struct task_struct *t)if (ret <0 ) goto out; ret =ckpt_obj_collect (ctx, nsproxy->ipc_ns,CKPT_OBJ_IPC_NS ); +if (ret <0 ) + goto out; +/* +* ipc_ns (shm) may keep references to files: if this is the +* first time we see this ipc_ns (ret > 0), proceed inside. +*/ +if (ret) + ret =ckpt_collect_ipc_ns (ctx, nsproxy->ipc_ns);/* TODO: collect other namespaces here */ out:
mm/shmem.c +1 -1
@@ -2387,7 +2387,7 @@ static int shmem_checkpoint(struct ckpt_ctx *ctx, struct vm_area_struct *vma) {enum vma_type vma_type;int ino_objref; -int first; +int first, ret;/* should be private anonymous ... verify that this is the case */ if (vma->vm_flags &CKPT_VMA_NOT_SUPPORTED ) {
Signature · 7 lines
1.6.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v18 53/80 c/r: support message-queues sysv-ipc
In reply to Oren LaadanCheckpoint of sysvipc message-queues is performed by iterating through all 'msq' objects and dumping the contents of each one. The message queued on each 'msq' are dumped with that object.
Message of a specific queue get written one by one. The queue lock cannot be held while dumping them, but the loop must be protected from someone (who ?) writing or reading. To do that we grab the lock, then hijack the entire chain of messages from the queue, drop the lock, and then safely dump them in a loop. Finally, with the lock held, we re-attach the chain while verifying that there isn't other (new) data on that queue.
Writing the message contents themselves is straight forward. The code is similar to that in ipc/msgutil.c, the main difference being that we deal with kernel memory and not user memory.
Changelog[v17]:
- Allocate security context for msg_msg
- Restore objects in the right namespace
- Don't unlock ipc before freeing
--- include/linux/checkpoint_hdr.h | 20 +++ ipc/Makefile | 3 +- ipc/checkpoint.c | 2 +- ipc/checkpoint_msg.c | 364 ++++++++++++++++++++++++++++++++++++++++ ipc/msg.c | 10 +- ipc/msgutil.c | 8 - ipc/util.h | 13 ++ 7 files changed, 403 insertions(+), 17 deletions(-) create mode 100644 ipc/checkpoint_msg.c
include/linux/checkpoint_hdr.h +20 -0
@@ -78,6 +78,7 @@ enum {CKPT_HDR_IPC =501 ,CKPT_HDR_IPC_SHM ,CKPT_HDR_IPC_MSG , +CKPT_HDR_IPC_MSG_MSG ,CKPT_HDR_IPC_SEM , CKPT_HDR_TAIL = 9001,
@@ -392,6 +393,25 @@ struct ckpt_hdr_ipc_shm {__u32 objref; } __attribute__((aligned(8))); +struct ckpt_hdr_ipc_msg { +struct ckpt_hdr h; +struct ckpt_hdr_ipc_perms perms; +__u64 q_stime; +__u64 q_rtime; +__u64 q_ctime; +__u64 q_cbytes; +__u64 q_qnum; +__u64 q_qbytes; +__s32 q_lspid; +__s32 q_lrpid; +} __attribute__((aligned (8 ))); + +struct ckpt_hdr_ipc_msg_msg { +struct ckpt_hdr h; +__s32 m_type; +__u32 m_ts; +} __attribute__((aligned (8 ))); +#define CKPT_TST_OVERFLOW_16 (a, b) \ ((sizeof(a) > sizeof(b)) && ((a) > SHORT_MAX))
ipc/Makefile +2 -1
@@ -9,4 +9,5 @@ obj_mq-$(CONFIG_COMPAT) += compat_mq.o obj-$(CONFIG_POSIX_MQUEUE) += mqueue.o msgutil.o $(obj_mq-y) obj-$(CONFIG_IPC_NS) += namespace.o obj-$(CONFIG_POSIX_MQUEUE_SYSCTL) += mq_sysctl.o -obj-$(CONFIG_SYSVIPC_CHECKPOINT) += checkpoint.o checkpoint_shm.o +obj-$(CONFIG_SYSVIPC_CHECKPOINT) += checkpoint.o \ + checkpoint_shm.o checkpoint_msg.o
ipc/checkpoint.c +1 -1
@@ -115,11 +115,11 @@ static int do_checkpoint_ipc_ns(struct ckpt_ctx *ctx, ret =checkpoint_ipc_any (ctx, ipc_ns,IPC_SHM_IDS ,CKPT_HDR_IPC_SHM , checkpoint_ipc_shm); -#if 0 /* NEXT FEW PATCHES */ if (ret <0 )return ret; ret =checkpoint_ipc_any (ctx, ipc_ns,IPC_MSG_IDS ,CKPT_HDR_IPC_MSG , checkpoint_ipc_msg); +#if 0 /* NEXT FEW PATCHES */ if (ret <0 )return ret; ret = checkpoint_ipc_any(ctx, ipc_ns, IPC_SEM_IDS,
ipc/checkpoint_msg.c new file +364 -0
364 lines not on this page · raw message
ipc/msg.c +3 -7
@@ -72,7 +72,6 @@ struct msg_sender {#define msg_unlock (msq) ipc_unlock(&(msq)->q_perm) -static void freeque (struct ipc_namespace *,struct kern_ipc_perm *);static int newque (struct ipc_namespace *,struct ipc_params *,int );#ifdef CONFIG_PROC_FS static int sysvipc_msg_proc_show (struct seq_file *s,void *it);
@@ -278,7 +277,7 @@ static void expunge_all(struct msg_queue *msq, int res)* msg_ids.rw_mutex (writer) and the spinlock for this message queue are held * before freeque() is called. msg_ids.rw_mutex remains locked on exit. */ -static void freeque (struct ipc_namespace *ns,struct kern_ipc_perm *ipcp) +void freeque (struct ipc_namespace *ns,struct kern_ipc_perm *ipcp) {struct list_head *tmp; struct msg_queue *msq = container_of(ipcp, struct msg_queue, q_perm);
@@ -311,14 +310,11 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)return security_msg_queue_associate (msq, msgflg); } -int do_msgget (key_t key,int msgflg,int req_id) +int do_msgget (struct ipc_namespace *ns,key_t key,int msgflg,int req_id) { -struct ipc_namespace *ns;struct ipc_ops msg_ops;struct ipc_params msg_params; - ns = current->nsproxy->ipc_ns; - msg_ops.getnew = newque; msg_ops.associate = msg_security; msg_ops.more_checks =NULL ;
@@ -331,7 +327,7 @@ int do_msgget(key_t key, int msgflg, int req_id) SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg) { -return do_msgget (key, msgflg,-1 ); +return do_msgget (current->nsproxy->ipc_ns, key, msgflg,-1 ); } static inline unsigned long
ipc/msgutil.c +0 -8
@@ -36,14 +36,6 @@ struct ipc_namespace init_ipc_ns = {atomic_t nr_ipc_ns =ATOMIC_INIT (1 ); -struct msg_msgseg { -struct msg_msgseg * next; -/* the next part of the message follows immediately */ -}; - -#define DATALEN_MSG (PAGE_SIZE-sizeof(struct msg_msg)) -#define DATALEN_SEG (PAGE_SIZE-sizeof(struct msg_msgseg)) -struct msg_msg *load_msg (const void __user *src,int len) {struct msg_msg *msg;
ipc/util.h +13 -0
@@ -141,6 +141,14 @@ extern void free_msg(struct msg_msg *msg);extern struct msg_msg *load_msg (const void __user *src,int len);extern int store_msg (void __user *dest,struct msg_msg *msg,int len); +struct msg_msgseg { +struct msg_msgseg *next; +/* the next part of the message follows immediately */ +}; + +#define DATALEN_MSG (PAGE_SIZE-sizeof(struct msg_msg)) +#define DATALEN_SEG (PAGE_SIZE-sizeof(struct msg_msgseg)) +extern void recompute_msgmni (struct ipc_namespace *);static inline int ipc_buildid (int id,int seq)
@@ -182,6 +190,8 @@ int do_shmget(struct ipc_namespace *ns, key_t key, size_t size, int shmflg, int req_id);void do_shm_rmid (struct ipc_namespace *ns,struct kern_ipc_perm *ipcp); +int do_msgget (struct ipc_namespace *ns,key_t key,int msgflg,int req_id); +void freeque (struct ipc_namespace *ns,struct kern_ipc_perm *ipcp);#ifdef CONFIG_CHECKPOINT extern int checkpoint_fill_ipc_perms(struct ckpt_hdr_ipc_perms *h,
@@ -192,6 +202,9 @@ extern int restore_load_ipc_perms(struct ckpt_hdr_ipc_perms *h,extern int ckpt_collect_ipc_shm (int id,void *p,void *data);extern int checkpoint_ipc_shm (int id,void *p,void *data);extern int restore_ipc_shm (struct ckpt_ctx *ctx,struct ipc_namespace *ns); + +extern int checkpoint_ipc_msg (int id,void *p,void *data); +extern int restore_ipc_msg (struct ckpt_ctx *ctx,struct ipc_namespace *ns);#endif #endif
Signature · 7 lines
1.6.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v18 54/80 c/r: support semaphore sysv-ipc
In reply to Oren LaadanCheckpoint of sysvipc semaphores is performed by iterating through all sem objects and dumping the contents of each one. The semaphore array of each sem is dumped with that object.
The semaphore array (sem->sem_base) holds an array of 'struct sem', which is a {int, int}. Because this translates into the same format on 32- and 64-bit architectures, the checkpoint format is simply the dump of this array as is.
TODO: this patch does not handle semaphore-undo -- this data should be saved per-task while iterating through the tasks.
Changelog[v18]:
- Handle kmalloc failure in restore_sem_array()
Changelog[v17]:
- Restore objects in the right namespace
- Forward declare struct msg_msg (instead of include linux/msg.h)
- Fix typo in comment
- Don't unlock ipc before calling freeary in error path
--- include/linux/checkpoint_hdr.h | 8 ++ ipc/Makefile | 2 +- ipc/checkpoint.c | 4 - ipc/checkpoint_sem.c | 221 ++++++++++++++++++++++++++++++++++++++++ ipc/sem.c | 11 +-- ipc/util.h | 8 ++ 6 files changed, 242 insertions(+), 12 deletions(-) create mode 100644 ipc/checkpoint_sem.c
include/linux/checkpoint_hdr.h +8 -0
@@ -412,6 +412,14 @@ struct ckpt_hdr_ipc_msg_msg {__u32 m_ts; } __attribute__((aligned(8))); +struct ckpt_hdr_ipc_sem { +struct ckpt_hdr h; +struct ckpt_hdr_ipc_perms perms; +__u64 sem_otime; +__u64 sem_ctime; +__u32 sem_nsems; +} __attribute__((aligned (8 ))); +#define CKPT_TST_OVERFLOW_16 (a, b) \ ((sizeof(a) > sizeof(b)) && ((a) > SHORT_MAX))
ipc/Makefile +1 -1
@@ -10,4 +10,4 @@ obj-$(CONFIG_POSIX_MQUEUE) += mqueue.o msgutil.o $(obj_mq-y) obj-$(CONFIG_IPC_NS) += namespace.o obj-$(CONFIG_POSIX_MQUEUE_SYSCTL) += mq_sysctl.o obj-$(CONFIG_SYSVIPC_CHECKPOINT) += checkpoint.o \ - checkpoint_shm.o checkpoint_msg.o + checkpoint_shm.o checkpoint_msg.o checkpoint_sem.o
ipc/checkpoint.c +0 -4
@@ -119,12 +119,10 @@ static int do_checkpoint_ipc_ns(struct ckpt_ctx *ctx,return ret; ret =checkpoint_ipc_any (ctx, ipc_ns,IPC_MSG_IDS ,CKPT_HDR_IPC_MSG , checkpoint_ipc_msg); -#if 0 /* NEXT FEW PATCHES */ if (ret <0 )return ret; ret =checkpoint_ipc_any (ctx, ipc_ns,IPC_SEM_IDS ,CKPT_HDR_IPC_SEM , checkpoint_ipc_sem); -#endif return ret; }
@@ -309,7 +307,6 @@ static struct ipc_namespace *do_restore_ipc_ns(struct ckpt_ctx *ctx) ret =restore_ipc_any (ctx, ipc_ns,IPC_SHM_IDS ,CKPT_HDR_IPC_SHM , restore_ipc_shm); -#if 0 /* NEXT FEW PATCHES */ if (ret <0 ) goto out; ret = restore_ipc_any(ctx, ipc_ns, IPC_MSG_IDS,
@@ -318,7 +315,6 @@ static struct ipc_namespace *do_restore_ipc_ns(struct ckpt_ctx *ctx) goto out; ret =restore_ipc_any (ctx, ipc_ns,IPC_SEM_IDS ,CKPT_HDR_IPC_SEM , restore_ipc_sem); -#endif if (ret <0 ) goto out;
ipc/checkpoint_sem.c new file +221 -0
221 lines not on this page · raw message
ipc/sem.c +4 -7
@@ -93,7 +93,6 @@#define sem_checkid (sma, semid) ipc_checkid(&sma->sem_perm, semid)static int newary (struct ipc_namespace *,struct ipc_params *,int ); -static void freeary (struct ipc_namespace *,struct kern_ipc_perm *);#ifdef CONFIG_PROC_FS static int sysvipc_sem_proc_show (struct seq_file *s,void *it);#endif
@@ -310,14 +309,12 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,return 0 ; } -int do_semget (key_t key,int nsems,int semflg,int req_id) +int do_semget (struct ipc_namespace *ns,key_t key,int nsems, +int semflg,int req_id) { -struct ipc_namespace *ns;struct ipc_ops sem_ops;struct ipc_params sem_params; - ns = current->nsproxy->ipc_ns; -if (nsems <0 || nsems > ns->sc_semmsl)return -EINVAL ;
@@ -334,7 +331,7 @@ int do_semget(key_t key, int nsems, int semflg, int req_id) SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg) { -return do_semget (key, nsems, semflg,-1 ); +return do_semget (current->nsproxy->ipc_ns, key, nsems, semflg,-1 ); }/*
@@ -521,7 +518,7 @@ static void free_un(struct rcu_head *head)* as a writer and the spinlock for this semaphore set hold. sem_ids.rw_mutex * remains locked on exit. */ -static void freeary (struct ipc_namespace *ns,struct kern_ipc_perm *ipcp) +void freeary (struct ipc_namespace *ns,struct kern_ipc_perm *ipcp) {struct sem_undo *un, *tu;struct sem_queue *q, *tq;
ipc/util.h +8 -0
@@ -193,6 +193,11 @@ void do_shm_rmid(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp);int do_msgget (struct ipc_namespace *ns,key_t key,int msgflg,int req_id);void freeque (struct ipc_namespace *ns,struct kern_ipc_perm *ipcp); +int do_semget (struct ipc_namespace *ns,key_t key,int nsems,int semflg, +int req_id); +void freeary (struct ipc_namespace *ns,struct kern_ipc_perm *ipcp); + +#ifdef CONFIG_CHECKPOINT extern int checkpoint_fill_ipc_perms (struct ckpt_hdr_ipc_perms *h,struct kern_ipc_perm *perm);
@@ -205,6 +210,9 @@ extern int restore_ipc_shm(struct ckpt_ctx *ctx, struct ipc_namespace *ns);extern int checkpoint_ipc_msg (int id,void *p,void *data);extern int restore_ipc_msg (struct ckpt_ctx *ctx,struct ipc_namespace *ns); + +extern int checkpoint_ipc_sem (int id,void *p,void *data); +extern int restore_ipc_sem (struct ckpt_ctx *ctx,struct ipc_namespace *ns);#endif #endif
Signature · 7 lines
1.6.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v18 55/80 c/r: (s390): expose a constant for the number of words (CRs)
In reply to Oren LaadanWe need to use this value in the checkpoint/restart code and would like to have a constant instead of a magic '3'.
Changelog:
Mar 30:
. Add CHECKPOINT_SUPPORT in Kconfig (Nathan Lynch)
Mar 03:
. Picked up additional use of magic '3' in ptrace.h
--- arch/s390/Kconfig | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
arch/s390/Kconfig +4 -0
@@ -49,6 +49,10 @@ config GENERIC_TIME_VSYSCALL config GENERIC_CLOCKEVENTS def_bool y +config CHECKPOINT_SUPPORT + bool + default y if 64BIT + config GENERIC_BUG bool depends on BUG
Signature · 7 lines
1.6.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v18 56/80 c/r: add CKPT_COPY() macro
In reply to Oren LaadanFrom: Dan Smith <[email protected]>
As suggested by Dave[1], this provides us a way to make the copy-in and copy-out processes symmetric. CKPT_COPY_ARRAY() provides us a way to do the same thing but for arrays. It's not critical, but it helps us unify the checkpoint and restart paths for some things.
Changelog:
Mar 04:
. Removed semicolons
. Added build-time check for __must_be_array in CKPT_COPY_ARRAY
Feb 27:
. Changed CKPT_COPY() to use assignment, eliminating the need
for the CKPT_COPY_BIT() macro
. Add CKPT_COPY_ARRAY() macro to help copying register arrays,
etc
. Move the macro definitions inside the CR #ifdef
Feb 25:
. Changed WARN_ON() to BUILD_BUG_ON()
1: https://lists.linux-foundation.org/pipermail/containers/2009-February/015821.html (all the way at the bottom)
--- include/linux/checkpoint.h | 29 +++++++++++++++++++++++++++++ 1 files changed, 29 insertions(+), 0 deletions(-)
include/linux/checkpoint.h +29 -0
@@ -238,6 +238,34 @@ static inline int ckpt_validate_errno(int errno)return (errno >=0 ) && (errno <MAX_ERRNO ); } +/* useful macros to copy fields and buffers to/from ckpt_hdr_xxx structures */ +#define CKPT_CPT 1 +#define CKPT_RST 2 + +#define CKPT_COPY (op,SAVE ,LIVE ) \ + do { \ + if (op == CKPT_CPT) \ + SAVE = LIVE; \ + else \ + LIVE = SAVE; \ + } while (0) + +/* +* Copy @count items from @LIVE to @SAVE if op is CKPT_CPT (otherwise, +* copy in the reverse direction) +*/ +#define CKPT_COPY_ARRAY (op,SAVE ,LIVE , count) \ + do { \ + (void)__must_be_array(SAVE); \ + (void)__must_be_array(LIVE); \ + BUILD_BUG_ON(sizeof(*SAVE) != sizeof(*LIVE)); \ + if (op == CKPT_CPT) \ + memcpy(SAVE, LIVE, count * sizeof(*SAVE)); \ + else \ + memcpy(LIVE, SAVE, count * sizeof(*SAVE)); \ + } while (0) + +/* debugging flags */ #define CKPT_DBASE 0x1/* anything */ #define CKPT_DSYS 0x2/* generic (system) */
@@ -270,6 +298,7 @@ extern unsigned long ckpt_debug_level;* CKPT_DBASE is the base flags, doesn't change * CKPT_DFLAG is to be redfined in each source file */ + #define ckpt_debug(fmt, args...) \ _ckpt_debug(CKPT_DBASE | CKPT_DFLAG, fmt, ## args)
Signature · 7 lines
1.6.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v18 57/80 c/r: define s390-specific checkpoint-restart code
In reply to Oren LaadanFrom: Dan Smith <[email protected]>
Implement the s390 arch-specific checkpoint/restart helpers. This is on top of Oren Laadan's c/r code.
With these, I am able to checkpoint and restart simple programs as per Oren's patch intro. While on x86 I never had to freeze a single task to checkpoint it, on s390 I do need to. That is a prereq for consistent snapshots (esp with multiple processes) anyway so I don't see that as a problem.
Changelog:
Jun 15:
. Fix checkpoint and restart compat wrappers
May 28:
. Export asm/checkpoint_hdr.h to userspace
. Define CKPT_ARCH_ID for S390
Apr 11:
. Introduce ckpt_arch_vdso()
Feb 27:
. Add checkpoint_s390.h
. Fixed up save and restore of PSW, with the non-address bits
properly masked out
Feb 25:
. Make checkpoint_hdr.h safe for inclusion in userspace . Replace comment about vsdo code
. Add comment about restoring access registers
. Write and read an empty ckpt_hdr_head_arch record to appease
code (mktree) that expects it to be there
. Utilize NUM_CKPT_WORDS in checkpoint_hdr.h
Feb 24:
. Use CKPT_COPY() to unify the un/loading of cpu and mm state . Fix fprs definition in ckpt_hdr_cpu
. Remove debug WARN_ON() from checkpoint.c
Feb 23:
. Macro-ize the un/packing of trace flags
. Fix the crash when externally-linked
. Break out the restart functions into restart.c
. Remove unneeded s390_enable_sie() call
Jan 30:
. Switched types in ckpt_hdr_cpu to __u64 etc.
(Per Oren suggestion)
. Replaced direct inclusion of structs in
ckpt_hdr_cpu with the struct members.
(Per Oren suggestion)
. Also ended up adding a bunch of new things
into restart (mm_segment, ksp, etc) in vain attempt to get code using fpu to not segfault after restart.
--- arch/s390/include/asm/Kbuild | 1 + arch/s390/include/asm/checkpoint_hdr.h | 89 +++++++++++++++ arch/s390/include/asm/unistd.h | 4 +- arch/s390/kernel/compat_wrapper.S | 14 +++ arch/s390/kernel/syscalls.S | 2 + arch/s390/mm/Makefile | 1 + arch/s390/mm/checkpoint.c | 194 ++++++++++++++++++++++++++++++++ arch/s390/mm/checkpoint_s390.h | 23 ++++ include/linux/checkpoint_hdr.h | 2 + 9 files changed, 329 insertions(+), 1 deletions(-) create mode 100644 arch/s390/include/asm/checkpoint_hdr.h create mode 100644 arch/s390/mm/checkpoint.c create mode 100644 arch/s390/mm/checkpoint_s390.h
arch/s390/include/asm/Kbuild +1 -0
@@ -8,6 +8,7 @@ header-y += ucontext.h header-y += vtoc.h header-y += zcrypt.h header-y += chsc.h +header-y += checkpoint_hdr.h unifdef-y += cmb.h unifdef-y += debug.h
arch/s390/include/asm/checkpoint_hdr.h new file +89 -0
89 lines not on this page · raw message
arch/s390/include/asm/unistd.h +3 -1
@@ -269,7 +269,9 @@#define __NR_pwritev 329#define __NR_rt_tgsigqueueinfo 330#define __NR_perf_counter_open 331 -#define NR_syscalls 332 +#define __NR_checkpoint 332 +#define __NR_restart 333 +#define NR_syscalls 334/* * There are some system calls that are not present on 64 bit, some
arch/s390/kernel/compat_wrapper.S +14 -0
@@ -1840,3 +1840,17 @@ sys_perf_counter_open_wrapper: lgfr %r5,%r5 # int llgfr %r6,%r6 # unsigned long jg sys_perf_counter_open # branch to system call + + .globl sys_checkpoint_wrapper +sys_checkpoint_wrapper: + lgfr %r2,%r2 # pid_t + lgfr %r3,%r3 # int + llgfr %r4,%r4 # unsigned long + jg compat_sys_checkpoint + + .globl sys_restore_wrapper +sys_restore_wrapper: + lgfr %r2,%r2 # int + lgfr %r3,%r3 # int + llgfr %r4,%r4 # unsigned long + jg compat_sys_restore
arch/s390/kernel/syscalls.S +2 -0
@@ -340,3 +340,5 @@ SYSCALL(sys_preadv,sys_preadv,compat_sys_preadv_wrapper) SYSCALL(sys_pwritev,sys_pwritev,compat_sys_pwritev_wrapper) SYSCALL(sys_rt_tgsigqueueinfo,sys_rt_tgsigqueueinfo,compat_sys_rt_tgsigqueueinfo_wrapper) /* 330 */ SYSCALL(sys_perf_counter_open,sys_perf_counter_open,sys_perf_counter_open_wrapper) +SYSCALL(sys_checkpoint,sys_checkpoint,sys_checkpoint_wrapper) +SYSCALL(sys_restart,sys_restart,sys_restore_wrapper)
arch/s390/mm/Makefile +1 -0
@@ -6,3 +6,4 @@ obj-y := init.o fault.o extmem.o mmap.o vmem.o pgtable.o maccess.o obj-$(CONFIG_CMM) += cmm.o obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o obj-$(CONFIG_PAGE_STATES) += page-states.o +obj-$(CONFIG_CHECKPOINT) += checkpoint.o
arch/s390/mm/checkpoint.c new file +194 -0
194 lines not on this page · raw message
arch/s390/mm/checkpoint_s390.h new file +23 -0
@@ -0,0 +1,23 @@ +/* +* Checkpoint/restart - architecture specific support for s390 +* +* Copyright IBM Corp. 2009 +* +* This file is subject to the terms and conditions of the GNU General Public +* License. See the file COPYING in the main directory of the Linux +* distribution for more details. +*/ + +#ifndef _S390_CHECKPOINT_H +#define _S390_CHECKPOINT_H + +#include <linux/checkpoint_hdr.h> +#include <linux/sched.h> +#include <linux/mm_types.h> + +extern void checkpoint_s390_regs (int op,struct ckpt_hdr_cpu *h, +struct task_struct *t); +extern void checkpoint_s390_mm (int op,struct ckpt_hdr_mm_context *h, +struct mm_struct *mm); + +#endif /* _S390_CHECKPOINT_H */
include/linux/checkpoint_hdr.h +2 -0
@@ -88,7 +88,9 @@ enum {/* architecture */ enum { +/* do not change order (will break ABI) */ CKPT_ARCH_X86_32 =1 , +CKPT_ARCH_S390X , };/* shared objrects (objref) */
Signature · 7 lines
1.6.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v18 58/80 c/r: clone_with_pids: define the s390 syscall
In reply to Oren LaadanFrom: Serge E. Hallyn <[email protected]>
Hook up the clone_with_pids system call for s390x. clone_with_pids() takes an additional argument over clone(), which we pass in through register 7. Stub code for using the syscall looks like:
struct target_pid_set {
int num_pids;
pid_t *target_pids;
unsigned long flags;
}; register unsigned long int __r2 asm ("2") = (unsigned long int)(stack);
register unsigned long int __r3 asm ("3") = (unsigned long int)(flags);
register unsigned long int __r4 asm ("4") = (unsigned long int)(NULL);
register unsigned long int __r5 asm ("5") = (unsigned long int)(NULL);
register unsigned long int __r6 asm ("6") = (unsigned long int)(NULL);
register unsigned long int __r7 asm ("7") = (unsigned long int)(setp);
register unsigned long int __result asm ("2");
__asm__ __volatile__(
" lghi %%r1,332\n"
" svc 0\n"
: "=d" (__result)
: "0" (__r2), "d" (__r3),
"d" (__r4), "d" (__r5), "d" (__r6), "d" (__r7)
: "1", "cc", "memory"
);
__result;
})
struct target_pid_set pid_set;
int pids[1] = { 19799 };
pid_set.num_pids = 1;
pid_set.target_pids = &pids[0];
pid_set.flags = 0;
rc = do_clone_with_pids(topstack, clone_flags, setp);
if (rc == 0)
printf("Child\n");
else if (rc > 0)
printf("Parent: child pid %d\n", rc);
else
printf("Error %d\n", rc);Changelog[v18]:
- Set return value for self-checkpoint
--- arch/s390/include/asm/unistd.h | 3 ++- arch/s390/kernel/compat_linux.c | 19 +++++++++++++++++++ arch/s390/kernel/process.c | 19 +++++++++++++++++++ arch/s390/kernel/syscalls.S | 1 + 4 files changed, 41 insertions(+), 1 deletions(-)
arch/s390/include/asm/unistd.h +2 -1
@@ -271,7 +271,8 @@#define __NR_perf_counter_open 331#define __NR_checkpoint 332#define __NR_restart 333 -#define NR_syscalls 334 +#define __NR_clone_with_pids 334 +#define NR_syscalls 335/* * There are some system calls that are not present on 64 bit, some
arch/s390/kernel/compat_linux.c +19 -0
@@ -818,6 +818,25 @@ asmlinkage long sys32_clone(void) parent_tidptr, child_tidptr); } +asmlinkage long sys32_clone_with_pids (void ) +{ +struct pt_regs *regs =task_pt_regs (current); +unsigned long clone_flags; +unsigned long newsp; +int __user *parent_tidptr, *child_tidptr; +void __user *upid_setp; + + clone_flags = regs->gprs[3 ] &0xffffffffUL ; + newsp = regs->orig_gpr2 &0x7fffffffUL ; + parent_tidptr =compat_ptr (regs->gprs[4 ]); + child_tidptr =compat_ptr (regs->gprs[5 ]); + upid_setp =compat_ptr (regs->gprs[7 ]); +if (!newsp) + newsp = regs->gprs[15 ]; +return do_fork_with_pids (clone_flags, newsp, regs,0 , + parent_tidptr, child_tidptr, upid_setp); +} +/* * 31 bit emulation wrapper functions for sys_fadvise64/fadvise64_64. * These need to rewrite the advise values for POSIX_FADV_{DONTNEED,NOREUSE}
arch/s390/kernel/process.c +19 -0
@@ -247,6 +247,25 @@ SYSCALL_DEFINE0(clone) parent_tidptr, child_tidptr); } +SYSCALL_DEFINE0 (clone_with_pids) +{ +struct pt_regs *regs =task_pt_regs (current); +unsigned long clone_flags; +unsigned long newsp; +int __user *parent_tidptr, *child_tidptr; +void __user *upid_setp; + + clone_flags = regs->gprs[3 ]; + newsp = regs->orig_gpr2; + parent_tidptr = (int __user *) regs->gprs[4 ]; + child_tidptr = (int __user *) regs->gprs[5 ]; + upid_setp = (void __user *) regs->gprs[7 ]; +if (!newsp) + newsp = regs->gprs[15 ]; +return do_fork_with_pids (clone_flags, newsp, regs,0 , parent_tidptr, + child_tidptr, upid_setp); +} +/* * This is trivial, and on the face of it looks like it * could equally well be done in user mode.
arch/s390/kernel/syscalls.S +1 -0
@@ -342,3 +342,4 @@ SYSCALL(sys_rt_tgsigqueueinfo,sys_rt_tgsigqueueinfo,compat_sys_rt_tgsigqueueinfo SYSCALL(sys_perf_counter_open,sys_perf_counter_open,sys_perf_counter_open_wrapper) SYSCALL(sys_checkpoint,sys_checkpoint,sys_checkpoint_wrapper) SYSCALL(sys_restart,sys_restart,sys_restore_wrapper) +SYSCALL(sys_clone_with_pids,sys_clone_with_pids,sys_clone_with_pids_wrapper)
Signature · 7 lines
1.6.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v18 59/80 c/r: capabilities: define checkpoint and restore fns
In reply to Oren LaadanFrom: Serge E. Hallyn <[email protected]>
[ Andrew: I am punting on dealing with the subsystem cooperation issues in this version, in favor of trying to get LSM issues straightened out ]
An application checkpoint image will store capability sets (and the bounding set) as __u64s. Define checkpoint and restart functions to translate between those and kernel_cap_t's.
Define a common function do_capset_tocred() which applies capability set changes to a passed-in struct cred.
The restore function uses do_capset_tocred() to apply the restored capabilities to the struct cred being crafted, subject to the current task's (task executing sys_restart()) permissions.
Changelog:
Jun 09: Can't choose securebits or drop bounding set if
file capabilities aren't compiled into the kernel. Also just store caps in __u32s (looks cleaner).
Jun 01: Made the checkpoint and restore functions and the
ckpt_hdr_capabilities struct more opaque to the rest of the c/r code, as suggested by Andrew Morgan, and using naming suggested by Oren.
Jun 01: Add commented BUILD_BUG_ON() to point out that the
current implementation depends on 64-bit capabilities. (Andrew Morgan and Alexey Dobriyan).
May 28: add helpers to c/r securebits
--- include/linux/capability.h | 6 ++ include/linux/checkpoint_hdr.h | 11 +++ kernel/capability.c | 164 +++++++++++++++++++++++++++++++++++++--- security/commoncap.c | 19 +---- 4 files changed, 172 insertions(+), 28 deletions(-)
include/linux/capability.h +6 -0
@@ -568,6 +568,12 @@ extern int capable(int cap);struct dentry ;extern int get_vfs_caps_from_disk (const struct dentry *dentry,struct cpu_vfs_cap_data *cpu_caps); +struct cred ; +int apply_securebits (unsigned securebits,struct cred *new); +struct ckpt_capabilities ; +int restore_capabilities (struct ckpt_capabilities *h,struct cred *new); +void checkpoint_capabilities (struct ckpt_capabilities *h,struct cred * cred); +#endif /* __KERNEL__ */ #endif /* !_LINUX_CAPABILITY_H */
include/linux/checkpoint_hdr.h +11 -0
@@ -61,6 +61,7 @@ enum {CKPT_HDR_NS ,CKPT_HDR_UTS_NS ,CKPT_HDR_IPC_NS , + CKPT_HDR_CAPABILITIES,/* 201-299: reserved for arch-dependent */
@@ -192,6 +193,16 @@ struct ckpt_hdr_task {__u64 robust_futex_list;/* a __user ptr */ } __attribute__((aligned(8))); +/* Posix capabilities */ +struct ckpt_capabilities { +__u32 cap_i_0, cap_i_1;/* inheritable set */ +__u32 cap_p_0, cap_p_1;/* permitted set */ +__u32 cap_e_0, cap_e_1;/* effective set */ +__u32 cap_b_0, cap_b_1;/* bounding set */ +__u32 securebits; +__u32 padding; +} __attribute__((aligned (8 ))); +/* namespaces */ struct ckpt_hdr_task_ns {struct ckpt_hdr h;
kernel/capability.c +153 -11
195 lines not on this page · raw message
security/commoncap.c +2 -17
@@ -893,24 +893,9 @@ int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3,* capability-based-privilege environment. */ case PR_SET_SECUREBITS : - error = -EPERM ; -if ((((new->securebits &SECURE_ALL_LOCKS ) >>1 ) - & (new->securebits ^ arg2))/*[1]*/ - || ((new->securebits &SECURE_ALL_LOCKS & ~arg2))/*[2]*/ - || (arg2 & ~(SECURE_ALL_LOCKS |SECURE_ALL_BITS ))/*[3]*/ - || (cap_capable (current,current_cred (),CAP_SETPCAP , -SECURITY_CAP_AUDIT ) !=0 )/*[4]*/ -/* -* [1] no changing of bits that are locked -* [2] no unlocking of locks -* [3] no setting of unsupported bits -* [4] doing anything requires privilege (go read about -* the "sendmail capabilities bug") -*/ - ) -/* cannot change a locked bit */ + error =apply_securebits (arg2, new); +if (error) goto error; - new->securebits = arg2; goto changed;case PR_GET_SECUREBITS :
Signature · 1 line
1.6.0.4
PATCH v18 60/80 c/r: checkpoint and restore task credentials
In reply to Oren LaadanFrom: Serge E. Hallyn <[email protected]>
This patch adds the checkpointing and restart of credentials (uids, gids, and capabilities) to Oren's c/r patchset (on top of v14). It goes to great pains to re-use (and define when needed) common helpers, in order to make sure that as security code is modified, the cr code will be updated. Some of the helpers should still be moved (i.e. _creds() functions should be in kernel/cred.c).
When building the credentials for the restarted process, I
1. create a new struct cred as a copy of the running task's cred (using prepare_cred())
2. always authorize any changes to the new struct cred based on the permissions of current_cred() (not the current transient state of the new cred).
While this may mean that certain transient_cred1->transient_cred2 states are allowed which otherwise wouldn't be allowed, the fact remains that current_cred() is allowed to transition to transient_cred2.
The reconstructed creds are applied to the task at the very end of the sys_restart call. This ensures that any objects which need to be re-created (file, socket, etc) are re-created using the creds of the task calling sys_restart - preventing an unpriv user from creating a privileged object, and ensuring that a root task can restart a process which had started out privileged, created some privileged objects, then dropped its privilege.
With these patches, the root user can restart checkpoint images (created by either hallyn or root) of user hallyn's tasks, resulting in a program owned by hallyn.
Changelog:
Sep 08: [NTL] discard const from struct cred * where appropriate Jun 15: Fix user_ns handling when !CONFIG_USER_N
Set creator_ref=0 for root_ns (discard @flags) Don't overwrite global user-ns if CONFIG_USER_NS
Jun 10: Merge with ckpt-v16-dev (Oren Laadan)
Jun 01: Don't check ordering of groups in group_info, bc
set_groups() will sort it for us.
May 28: 1. Restore securebits
2. Address Alexey's comments: move prototypes out of sched.h, validate ngroups < NGROUPS_MAX, validate groups are sorted, and get rid of ckpt_hdr_cred->version.
3. remove bogus unused flag RESTORE_CREATE_USERNS
May 26: Move group, user, userns, creds c/r functions out
of checkpoint/process.c and into the appropriate files.
May 26: Define struct ckpt_hdr_task_creds and move task cred
objref c/r into {checkpoint_restore}_task_shared().
May 26: Take cred refs around checkpoint_write_creds() May 20: Remove the limit on number of groups in groupinfo
at checkpoint time
May 20: Remove the depth limit on empty user namespaces May 20: Better document checkpoint_user
May 18: fix more refcounting: if (userns 5, uid 0) had
no active tasks or child user_namespaces, then it shouldn't exist at restart or it, its namespace, and its whole chain of creators will be leaked.
May 14: fix some refcounting:
1. a new user_ns needs a ref to remain pinned
by its root user
2. current_user_ns needs an extra ref bc objhash drops two on restart
3. cred needs a ref for the real credentials bc commit_creds eats one ref.
May 13: folded in fix to userns refcounting.
--- checkpoint/namespace.c | 41 ++++++++++ checkpoint/objhash.c | 82 ++++++++++++++++++++ checkpoint/process.c | 111 ++++++++++++++++++++++++++- include/linux/capability.h | 6 +- include/linux/checkpoint.h | 12 +++ include/linux/checkpoint_hdr.h | 59 ++++++++++++++ include/linux/checkpoint_types.h | 2 + kernel/cred.c | 123 +++++++++++++++++++++++++++++ kernel/groups.c | 69 +++++++++++++++++ kernel/user.c | 158 ++++++++++++++++++++++++++++++++++++++ kernel/user_namespace.c | 89 +++++++++++++++++++++ 11 files changed, 746 insertions(+), 6 deletions(-)
checkpoint/namespace.c +41 -0
@@ -98,3 +98,44 @@ void *restore_uts_ns(struct ckpt_ctx *ctx) {return (void *)do_restore_uts_ns (ctx); } + +/* +* user_ns - trivial checkpoint/restore for !CONFIG_USER_NS case +*/ +#ifndef CONFIG_USER_NS +int checkpoint_userns (struct ckpt_ctx *ctx,void *ptr) +{ +struct ckpt_hdr_user_ns *h; +int ret; + + h =ckpt_hdr_get_type (ctx,sizeof (*h),CKPT_HDR_USER_NS ); +if (!h) +return -ENOMEM ; + ret =ckpt_write_obj (ctx, (struct ckpt_hdr *) h); +ckpt_hdr_put (ctx, h); +return ret; +} + +void *restore_userns (struct ckpt_ctx *ctx) +{ +struct ckpt_hdr_user_ns *h; +struct user_namespace *ns; + +/* complain if image contains multiple namespaces */ +if (ctx->stats.user_ns) +return ERR_PTR (-EEXIST ); + + h =ckpt_read_obj_type (ctx,sizeof (*h),CKPT_HDR_USER_NS ); +if (IS_ERR (h)) +return ERR_PTR (PTR_ERR (h)); + +if (h->creator_ref) + ns =ERR_PTR (-EINVAL ); +else + ns =get_user_ns (current_user_ns ()); + + ctx->stats.user_ns++; +ckpt_hdr_put (ctx, h); +return ns; +} +#endif
checkpoint/objhash.c +82 -0
100 lines not on this page · raw message
checkpoint/process.c +108 -3
153 lines not on this page · raw message
include/linux/capability.h +3 -3
@@ -569,10 +569,10 @@ struct dentry;extern int get_vfs_caps_from_disk (const struct dentry *dentry,struct cpu_vfs_cap_data *cpu_caps);struct cred ; -int apply_securebits (unsigned securebits,struct cred *new); +extern int apply_securebits (unsigned securebits,struct cred *new);struct ckpt_capabilities ; -int restore_capabilities (struct ckpt_capabilities *h,struct cred *new); -void checkpoint_capabilities (struct ckpt_capabilities *h,struct cred * cred); +extern int restore_capabilities (struct ckpt_capabilities *h,struct cred *new); +extern void checkpoint_capabilities (struct ckpt_capabilities *h,struct cred *cred);#endif /* __KERNEL__ */
include/linux/checkpoint.h +12 -0
@@ -25,6 +25,7 @@#include <linux/sched.h> #include <linux/nsproxy.h> #include <linux/ipc_namespace.h> +#include <linux/user_namespace.h> #include <linux/checkpoint_types.h> #include <linux/checkpoint_hdr.h> #include <linux/err.h>
@@ -192,6 +193,17 @@ extern int checkpoint_file_common(struct ckpt_ctx *ctx, struct file *file,extern int restore_file_common (struct ckpt_ctx *ctx,struct file *file,struct ckpt_hdr_file *h); +/* credentials */ +extern int checkpoint_groupinfo (struct ckpt_ctx *ctx,void *ptr); +extern int checkpoint_user (struct ckpt_ctx *ctx,void *ptr); +extern int checkpoint_cred (struct ckpt_ctx *ctx,void *ptr); +extern void *restore_groupinfo (struct ckpt_ctx *ctx); +extern void *restore_user (struct ckpt_ctx *ctx); +extern void *restore_cred (struct ckpt_ctx *ctx); + +extern int checkpoint_userns (struct ckpt_ctx *ctx,void *ptr); +extern void *restore_userns (struct ckpt_ctx *ctx); +/* memory */ extern void ckpt_pgarr_free (struct ckpt_ctx *ctx);
include/linux/checkpoint_hdr.h +59 -0
89 lines not on this page · raw message
include/linux/checkpoint_types.h +2 -0
@@ -25,6 +25,7 @@struct ckpt_stats {int uts_ns;int ipc_ns; +int user_ns; };struct ckpt_ctx {
@@ -70,6 +71,7 @@ struct ckpt_ctx {int active_pid;/* (next) position in pids array */ struct completion complete;/* container root and other tasks on */ wait_queue_head_t waitq;/* start, end, and restart ordering */ +struct cred *realcred, *ecred;/* tmp storage for cred at restart */ struct ckpt_stats stats;/* statistics */ };
kernel/cred.c +123 -0
132 lines not on this page · raw message
kernel/groups.c +69 -0
78 lines not on this page · raw message
kernel/user.c +158 -0
167 lines not on this page · raw message
kernel/user_namespace.c +89 -0
98 lines not on this page · raw message
Signature · 7 lines
1.6.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v18 61/80 c/r: restore file->f_cred
In reply to Oren LaadanFrom: Serge E. Hallyn <[email protected]>
Restore a file's f_cred. This is set to the cred of the task doing the open, so often it will be the same as that of the restarted task.
Changelog[v1]:
- [Nathan Lynch] discard const from struct cred * where appropriate
--- checkpoint/files.c | 18 ++++++++++++++++-- include/linux/checkpoint_hdr.h | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-)
checkpoint/files.c +16 -2
@@ -147,12 +147,18 @@ static int scan_fds(struct files_struct *files, int **fdtable)int checkpoint_file_common (struct ckpt_ctx *ctx,struct file *file,struct ckpt_hdr_file *h) { +struct cred *f_cred = (struct cred *) file->f_cred; + h->f_flags = file->f_flags; h->f_mode = file->f_mode; h->f_pos = file->f_pos; h->f_version = file->f_version; -/* FIX: need also file->uid, file->gid, file->f_owner, etc */ + h->f_credref =checkpoint_obj (ctx, f_cred,CKPT_OBJ_CRED ); +if (h->f_credref <0 ) +return h->f_credref; + +/* FIX: need also file->f_owner, etc */ return 0 ; }
@@ -489,8 +495,16 @@ int restore_file_common(struct ckpt_ctx *ctx, struct file *file,fmode_t new_mode = file->f_mode;fmode_t saved_mode = (__force fmode_t ) h->f_mode;int ret; +struct cred *cred; + +/* FIX: need to restore owner etc */ -/* FIX: need to restore uid, gid, owner etc */ +/* restore the cred */ + cred =ckpt_obj_fetch (ctx, h->f_credref,CKPT_OBJ_CRED ); +if (IS_ERR (cred)) +return PTR_ERR (cred); +put_cred (file->f_cred); + file->f_cred =get_cred (cred);/* safe to set 1st arg (fd) to 0, as command is F_SETFL */ ret =vfs_fcntl (0 ,F_SETFL , h->f_flags &CKPT_SETFL_MASK , file);
include/linux/checkpoint_hdr.h +1 -1
@@ -350,7 +350,7 @@ struct ckpt_hdr_file {__u32 f_type;__u32 f_mode;__u32 f_flags; -__u32 _padding; +__s32 f_credref;__u64 f_pos;__u64 f_version; } __attribute__((aligned(8)));
Signature · 7 lines
1.6.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v18 62/80 c/r: checkpoint and restore (shared) task's sighand_struct
In reply to Oren LaadanThis patch adds the checkpointing and restart of signal handling state - 'struct sighand_struct'. Since the contents of this state only affect userspace, no input validation is required.
Add _NSIG to kernel constants saved/tested with image header.
Number of signals (_NSIG) is arch-dependent, but is within __KERNEL__ and not visibile to userspace compile. Therefore, define per arch CKPT_ARCH_NSIG in <asm/checkpoint_hdr.h>.
Changelog[v1]:
- Rename headerless struct ckpt_hdr_* to struct ckpt_*
--- arch/s390/include/asm/checkpoint_hdr.h | 8 ++ arch/x86/include/asm/checkpoint_hdr.h | 8 ++ checkpoint/Makefile | 3 +- checkpoint/checkpoint.c | 2 + checkpoint/objhash.c | 26 +++++ checkpoint/process.c | 19 ++++ checkpoint/restart.c | 3 + checkpoint/signal.c | 163 ++++++++++++++++++++++++++++++++ include/linux/checkpoint.h | 9 ++- include/linux/checkpoint_hdr.h | 22 +++++ 10 files changed, 261 insertions(+), 2 deletions(-) create mode 100644 checkpoint/signal.c
arch/s390/include/asm/checkpoint_hdr.h +8 -0
@@ -82,6 +82,14 @@ struct ckpt_hdr_mm_context {unsigned long asce_limit; }; +#define CKPT_ARCH_NSIG 64 +#ifdef __KERNEL__ +#include <asm/signal.h> +#if CKPT_ARCH_NSIG != _SIGCONTEXT_NSIG +#error CKPT_ARCH_NSIG size is wrong (asm/sigcontext.h and asm/checkpoint_hdr.h) +#endif +#endif +struct ckpt_hdr_header_arch {struct ckpt_hdr h; };
arch/x86/include/asm/checkpoint_hdr.h +8 -0
@@ -48,6 +48,14 @@ enum { CKPT_HDR_MM_CONTEXT_LDT, }; +#define CKPT_ARCH_NSIG 64 +#ifdef __KERNEL__ +#include <asm/signal.h> +#if CKPT_ARCH_NSIG != _NSIG +#error CKPT_ARCH_NSIG size is wrong per asm/signal.h and asm/checkpoint_hdr.h +#endif +#endif +struct ckpt_hdr_header_arch {struct ckpt_hdr h;/* FIXME: add HAVE_HWFP */
checkpoint/Makefile +2 -1
@@ -10,4 +10,5 @@ obj-$(CONFIG_CHECKPOINT) += \ process.o \ namespace.o \ files.o \ - memory.o + memory.o \ + signal.o
checkpoint/checkpoint.c +2 -0
@@ -288,6 +288,8 @@ static void fill_kernel_const(struct ckpt_const *h) h->task_comm_len =sizeof (tsk->comm);/* mm */ h->mm_saved_auxv_len =sizeof (mm->saved_auxv); +/* signal */ + h->signal_nsig = _NSIG;/* uts */ h->uts_sysname_len =sizeof (uts->sysname); h->uts_nodename_len =sizeof (uts->nodename);
checkpoint/objhash.c +26 -0
@@ -125,6 +125,22 @@ static int obj_mm_users(void *ptr)return atomic_read (&((struct mm_struct *) ptr)->mm_users); } +static int obj_sighand_grab (void *ptr) +{ +atomic_inc (&((struct sighand_struct *) ptr)->count); +return 0 ; +} + +static void obj_sighand_drop (void *ptr,int lastref) +{ +__cleanup_sighand ((struct sighand_struct *) ptr); +} + +static int obj_sighand_users (void *ptr) +{ +return atomic_read (&((struct sighand_struct *) ptr)->count); +} +static int obj_ns_grab (void *ptr) {get_nsproxy ((struct nsproxy *) ptr);
@@ -263,6 +279,16 @@ static struct ckpt_obj_ops ckpt_obj_ops[] = { .checkpoint = checkpoint_mm, .restore = restore_mm, }, +/* sighand object */ + { + .obj_name = "SIGHAND", + .obj_type = CKPT_OBJ_SIGHAND, + .ref_drop = obj_sighand_drop, + .ref_grab = obj_sighand_grab, + .ref_users = obj_sighand_users, + .checkpoint = checkpoint_sighand, + .restore = restore_sighand, + },/* ns object */ { .obj_name = "NSPROXY",
checkpoint/process.c +19 -0
@@ -181,6 +181,7 @@ static int checkpoint_task_objs(struct ckpt_ctx *ctx, struct task_struct *t)struct ckpt_hdr_task_objs *h;int files_objref;int mm_objref; +int sighand_objref;int ret;/*
@@ -214,11 +215,19 @@ static int checkpoint_task_objs(struct ckpt_ctx *ctx, struct task_struct *t)return mm_objref; } + sighand_objref =checkpoint_obj_sighand (ctx, t); +ckpt_debug ("sighand: objref %d\n" , sighand_objref); +if (sighand_objref <0 ) { +ckpt_write_err (ctx,"TE" ,"sighand_struct" , sighand_objref); +return sighand_objref; + } + h =ckpt_hdr_get_type (ctx,sizeof (*h),CKPT_HDR_TASK_OBJS );if (!h)return -ENOMEM ; h->files_objref = files_objref; h->mm_objref = mm_objref; + h->sighand_objref = sighand_objref; ret =ckpt_write_obj (ctx, &h->h);ckpt_hdr_put (ctx, h);
@@ -382,6 +391,9 @@ int ckpt_collect_task(struct ckpt_ctx *ctx, struct task_struct *t)if (ret <0 )return ret; ret =ckpt_collect_mm (ctx, t); +if (ret <0 ) +return ret; + ret =ckpt_collect_sighand (ctx, t);return ret; }
@@ -529,10 +541,17 @@ static int restore_task_objs(struct ckpt_ctx *ctx) ret =restore_obj_file_table (ctx, h->files_objref);ckpt_debug ("file_table: ret %d (%p)\n" , ret, current->files); +if (ret <0 ) + goto out; ret =restore_obj_mm (ctx, h->mm_objref);ckpt_debug ("mm: ret %d (%p)\n" , ret, current->mm); +if (ret <0 ) + goto out; + ret =restore_obj_sighand (ctx, h->sighand_objref); +ckpt_debug ("sighand: ret %d (%p)\n" , ret, current->sighand); + out:ckpt_hdr_put (ctx, h);return ret; }
checkpoint/restart.c +3 -0
@@ -383,6 +383,9 @@ static int check_kernel_const(struct ckpt_const *h)/* mm */ if (h->mm_saved_auxv_len !=sizeof (mm->saved_auxv))return -EINVAL ; +/* signal */ +if (h->signal_nsig != _NSIG) +return -EINVAL ;/* uts */ if (h->uts_sysname_len !=sizeof (uts->sysname))return -EINVAL ;
checkpoint/signal.c new file +163 -0
163 lines not on this page · raw message
include/linux/checkpoint.h +8 -1
@@ -245,6 +245,14 @@ extern int restore_memory_contents(struct ckpt_ctx *ctx, struct inode *inode); VM_RESERVED | VM_NORESERVE | VM_HUGETLB | VM_NONLINEAR | \ VM_MAPPED_COPY | VM_INSERTPAGE | VM_MIXEDMAP | VM_SAO) +/* signals */ +extern int checkpoint_obj_sighand (struct ckpt_ctx *ctx,struct task_struct *t); +extern int restore_obj_sighand (struct ckpt_ctx *ctx,int sighand_objref); + +extern int ckpt_collect_sighand (struct ckpt_ctx *ctx,struct task_struct *t); +extern int checkpoint_sighand (struct ckpt_ctx *ctx,void *ptr); +extern void *restore_sighand (struct ckpt_ctx *ctx); +static inline int ckpt_validate_errno (int errno) {return (errno >=0 ) && (errno <MAX_ERRNO );
@@ -277,7 +285,6 @@ static inline int ckpt_validate_errno(int errno)memcpy (LIVE ,SAVE , count *sizeof (*SAVE )); \ }while (0 ) - /* debugging flags */#define CKPT_DBASE 0x1/* anything */ #define CKPT_DSYS 0x2/* generic (system) */
include/linux/checkpoint_hdr.h +22 -0
@@ -87,6 +87,8 @@ enum {CKPT_HDR_IPC_MSG_MSG ,CKPT_HDR_IPC_SEM , +CKPT_HDR_SIGHAND =601 , +CKPT_HDR_TAIL =9001 , CKPT_HDR_ERROR = 9999,
@@ -113,6 +115,7 @@ enum obj_type {CKPT_OBJ_FILE_TABLE ,CKPT_OBJ_FILE ,CKPT_OBJ_MM , +CKPT_OBJ_SIGHAND ,CKPT_OBJ_NS ,CKPT_OBJ_UTS_NS , CKPT_OBJ_IPC_NS,
@@ -129,6 +132,8 @@ struct ckpt_const {__u16 task_comm_len;/* mm */ __u16 mm_saved_auxv_len; +/* signal */ +__u16 signal_nsig;/* uts */ __u16 uts_sysname_len;__u16 uts_nodename_len;
@@ -299,6 +304,7 @@ struct ckpt_hdr_task_objs {__s32 files_objref;__s32 mm_objref; +__s32 sighand_objref; } __attribute__((aligned(8)));/* restart blocks */
@@ -414,6 +420,22 @@ struct ckpt_hdr_pgarr {__u64 nr_pages;/* number of pages to saved */ } __attribute__((aligned(8))); +/* signals */ +struct ckpt_sigset { +__u8 sigset[CKPT_ARCH_NSIG /8 ]; +} __attribute__((aligned (8 ))); + +struct ckpt_sigaction { +__u64 _sa_handler; +__u64 sa_flags; +__u64 sa_restorer; +struct ckpt_sigset sa_mask; +} __attribute__((aligned (8 ))); + +struct ckpt_hdr_sighand { +struct ckpt_hdr h; +struct ckpt_sigaction action[0 ]; +} __attribute__((aligned (8 )));/* ipc commons */ struct ckpt_hdr_ipcns {
Signature · 7 lines
1.6.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v18 63/80 c/r: [signal 1/4] blocked and template for shared signals
In reply to Oren LaadanThis patch adds checkpoint/restart of blocked signals mask (t->blocked) and a template for shared signals (t->signal).
Because t->signal sharing is tied to threads, we ensure proper sharing of t->signal (struct signal_struct) for threads only.
Access to t->signal is protected by locking t->sighand->lock. Therefore, the usual checkpoint_obj() invoking the callback checkpoint_signal(ctx, signal) is insufficient because the task pointer is unavailable.
Instead, handling of t->signal sharing is explicit using helpers like ckpt_obj_lookup_add(), ckpt_obj_fetch() and ckpt_obj_insert(). The actual state is saved (if needed) _after_ the task_objs data.
To prevent tasks from handling restored signals during restart, set their mask to block all signals and only restore the original mask at the very end (before the last sync point).
Introduce per-task pointer 'ckpt_data' to temporary store data for restore actions that are deferred to the end (like restoring the signal block mask).
--- checkpoint/objhash.c | 7 +++ checkpoint/process.c | 64 ++++++++++++++++++++++++- checkpoint/signal.c | 104 ++++++++++++++++++++++++++++++++++++++++ include/linux/checkpoint.h | 6 ++ include/linux/checkpoint_hdr.h | 14 +++++- 5 files changed, 193 insertions(+), 2 deletions(-)
checkpoint/objhash.c +7 -0
@@ -289,6 +289,13 @@ static struct ckpt_obj_ops ckpt_obj_ops[] = { .checkpoint = checkpoint_sighand, .restore = restore_sighand, }, +/* signal object */ + { + .obj_name = "SIGNAL", + .obj_type = CKPT_OBJ_SIGNAL, + .ref_drop = obj_no_drop, + .ref_grab = obj_no_grab, + },/* ns object */ { .obj_name = "NSPROXY",
checkpoint/process.c +63 -1
113 lines not on this page · raw message
checkpoint/signal.c +104 -0
107 lines not on this page · raw message
include/linux/checkpoint.h +6 -0
@@ -253,6 +253,12 @@ extern int ckpt_collect_sighand(struct ckpt_ctx *ctx, struct task_struct *t);extern int checkpoint_sighand (struct ckpt_ctx *ctx,void *ptr);extern void *restore_sighand (struct ckpt_ctx *ctx); +extern int checkpoint_obj_signal (struct ckpt_ctx *ctx,struct task_struct *t); +extern int restore_obj_signal (struct ckpt_ctx *ctx,int signal_objref); + +extern int checkpoint_task_signal (struct ckpt_ctx *ctx,struct task_struct *t); +extern int restore_task_signal (struct ckpt_ctx *ctx); +static inline int ckpt_validate_errno (int errno) {return (errno >=0 ) && (errno <MAX_ERRNO );
include/linux/checkpoint_hdr.h +13 -1
@@ -88,6 +88,8 @@ enum {CKPT_HDR_IPC_SEM ,CKPT_HDR_SIGHAND =601 , +CKPT_HDR_SIGNAL , +CKPT_HDR_SIGNAL_TASK , CKPT_HDR_TAIL = 9001,
@@ -116,6 +118,7 @@ enum obj_type {CKPT_OBJ_FILE ,CKPT_OBJ_MM ,CKPT_OBJ_SIGHAND , +CKPT_OBJ_SIGNAL ,CKPT_OBJ_NS ,CKPT_OBJ_UTS_NS , CKPT_OBJ_IPC_NS,
@@ -210,7 +213,6 @@ struct ckpt_hdr_task {__u32 compat_robust_futex_list;/* a compat __user ptr */ __u32 robust_futex_head_len;__u64 robust_futex_list;/* a __user ptr */ - } __attribute__((aligned(8)));/* Posix capabilities */
@@ -305,6 +307,7 @@ struct ckpt_hdr_task_objs {__s32 files_objref;__s32 mm_objref;__s32 sighand_objref; +__s32 signal_objref; } __attribute__((aligned(8)));/* restart blocks */
@@ -437,6 +440,15 @@ struct ckpt_hdr_sighand {struct ckpt_sigaction action[0 ]; } __attribute__((aligned(8))); +struct ckpt_hdr_signal { +struct ckpt_hdr h; +} __attribute__((aligned (8 ))); + +struct ckpt_hdr_signal_task { +struct ckpt_hdr h; +struct ckpt_sigset blocked; +} __attribute__((aligned (8 ))); +/* ipc commons */ struct ckpt_hdr_ipcns {struct ckpt_hdr h;
Signature · 7 lines
1.6.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v18 64/80 c/r: [signal 2/4] checkpoint/restart of rlimit
In reply to Oren LaadanThis patch adds checkpoint and restart of rlimit information that is part of shared signal_struct.
--- checkpoint/checkpoint.c | 2 ++ checkpoint/restart.c | 3 +++ checkpoint/signal.c | 27 +++++++++++++++++++++++---- include/linux/checkpoint_hdr.h | 17 +++++++++++++++++ include/linux/resource.h | 4 ++++ kernel/sys.c | 36 +++++++++++++++++++++++------------- 6 files changed, 72 insertions(+), 17 deletions(-)
checkpoint/checkpoint.c +2 -0
@@ -297,6 +297,8 @@ static void fill_kernel_const(struct ckpt_const *h) h->uts_version_len =sizeof (uts->version); h->uts_machine_len =sizeof (uts->machine); h->uts_domainname_len =sizeof (uts->domainname); +/* rlimit */ + h->rlimit_nlimits =RLIM_NLIMITS ; }/* write the checkpoint header */
checkpoint/restart.c +3 -0
@@ -399,6 +399,9 @@ static int check_kernel_const(struct ckpt_const *h)return -EINVAL ;if (h->uts_domainname_len !=sizeof (uts->domainname))return -EINVAL ; +/* rlimit */ +if (h->rlimit_nlimits !=RLIM_NLIMITS ) +return -EINVAL ;return 0 ; }
checkpoint/signal.c +23 -4
@@ -14,6 +14,7 @@#include <linux/sched.h> #include <linux/signal.h> #include <linux/errno.h> +#include <linux/resource.h> #include <linux/checkpoint.h> #include <linux/checkpoint_hdr.h>
@@ -169,13 +170,22 @@ int restore_obj_sighand(struct ckpt_ctx *ctx, int sighand_objref)static int checkpoint_signal (struct ckpt_ctx *ctx,struct task_struct *t) {struct ckpt_hdr_signal *h; +struct signal_struct *signal; +struct rlimit *rlim;int ret; h =ckpt_hdr_get_type (ctx,sizeof (*h),CKPT_HDR_SIGNAL );if (!h)return -ENOMEM ; -/* fill in later */ + signal = t->signal; + rlim = signal->rlim; + +/* rlimit */ +for (i =0 ; i <RLIM_NLIMITS ; i++) { + h->rlim[i].rlim_cur = rlim[i].rlim_cur; + h->rlim[i].rlim_max = rlim[i].rlim_max; + } ret =ckpt_write_obj (ctx, &h->h);ckpt_hdr_put (ctx, h);
@@ -191,15 +201,24 @@ int checkpoint_obj_signal(struct ckpt_ctx *ctx, struct task_struct *t)static int restore_signal (struct ckpt_ctx *ctx) {struct ckpt_hdr_signal *h; +struct rlimit rlim; +int i, ret; h =ckpt_read_obj_type (ctx,sizeof (*h),CKPT_HDR_SIGNAL );if (IS_ERR (h))return PTR_ERR (h); -/* fill in later */ - +/* rlimit */ +for (i =0 ; i <RLIM_NLIMITS ; i++) { + rlim.rlim_cur = h->rlim[i].rlim_cur; + rlim.rlim_max = h->rlim[i].rlim_max; + ret =do_setrlimit (i, &rlim); +if (ret <0 ) +break ; + } + out:ckpt_hdr_put (ctx, h); -return 0 ; +return ret; }int restore_obj_signal (struct ckpt_ctx *ctx,int signal_objref)
include/linux/checkpoint_hdr.h +17 -0
@@ -144,6 +144,8 @@ struct ckpt_const {__u16 uts_version_len;__u16 uts_machine_len;__u16 uts_domainname_len; +/* rlimit */ +__u16 rlimit_nlimits; } __attribute__((aligned(8)));/* checkpoint image header */
@@ -440,8 +442,23 @@ struct ckpt_hdr_sighand {struct ckpt_sigaction action[0 ]; } __attribute__((aligned(8))); +struct ckpt_rlimit { +__u64 rlim_cur; +__u64 rlim_max; +} __attribute__((aligned (8 ))); + +/* cannot include <linux/resource.h> from userspace, so define: */ +#define CKPT_RLIM_NLIMITS 16 +#ifdef __KERNEL__ +#include <linux/resource.h> +#if CKPT_RLIM_NLIMITS !=RLIM_NLIMITS +#error CKPT_RLIM_NLIMIT size is wrong per asm-generic/resource.h +#endif +#endif +struct ckpt_hdr_signal {struct ckpt_hdr h; +struct ckpt_rlimit rlim[CKPT_RLIM_NLIMITS ]; } __attribute__((aligned (8 )));struct ckpt_hdr_signal_task {
include/linux/resource.h +4 -0
@@ -72,4 +72,8 @@ struct rlimit {int getrusage (struct task_struct *p,int who,struct rusage __user *ru); +#ifdef __KERNEL__ +extern int do_setrlimit (unsigned int resource,struct rlimit *rlim); +#endif +#endif
kernel/sys.c +23 -13
@@ -1144,40 +1144,39 @@ SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,#endif -SYSCALL_DEFINE2(setrlimit, unsigned int, resource, struct rlimit __user *, rlim) +int do_setrlimit (unsigned int resource,struct rlimit *new_rlim) { -struct rlimit new_rlim, *old_rlim; +struct rlimit *old_rlim;int retval;if (resource >=RLIM_NLIMITS )return -EINVAL ; -if (copy_from_user (&new_rlim, rlim,sizeof (*rlim))) -return -EFAULT ; -if (new_rlim.rlim_cur > new_rlim.rlim_max) +if (new_rlim->rlim_cur > new_rlim->rlim_max)return -EINVAL ; + old_rlim = current->signal->rlim + resource; -if ((new_rlim.rlim_max > old_rlim->rlim_max) && +if ((new_rlim->rlim_max > old_rlim->rlim_max) && !capable (CAP_SYS_RESOURCE ))return -EPERM ; -if (resource ==RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open) +if (resource ==RLIMIT_NOFILE && new_rlim->rlim_max > sysctl_nr_open)return -EPERM ; - retval =security_task_setrlimit (resource, &new_rlim); + retval =security_task_setrlimit (resource, new_rlim);if (retval)return retval; -if (resource ==RLIMIT_CPU && new_rlim.rlim_cur ==0 ) { +if (resource ==RLIMIT_CPU && new_rlim->rlim_cur ==0 ) {/* * The caller is asking for an immediate RLIMIT_CPU * expiry. But we use the zero value to mean "it was * never set". So let's cheat and make it one second * instead */ - new_rlim.rlim_cur =1 ; + new_rlim->rlim_cur =1 ; }task_lock (current->group_leader); - *old_rlim = new_rlim; + *old_rlim = *new_rlim;task_unlock (current->group_leader);if (resource !=RLIMIT_CPU )
@@ -1189,14 +1188,25 @@ SYSCALL_DEFINE2(setrlimit, unsigned int, resource, struct rlimit __user *, rlim)* very long-standing error, and fixing it now risks breakage of * applications, so we live with it */ -if (new_rlim.rlim_cur ==RLIM_INFINITY ) +if (new_rlim->rlim_cur ==RLIM_INFINITY ) goto out; -update_rlimit_cpu (new_rlim.rlim_cur); +update_rlimit_cpu (new_rlim->rlim_cur); out:return 0 ; } +SYSCALL_DEFINE2(setrlimit, unsigned int, resource, struct rlimit __user *, rlim) +{ +struct rlimit new_rlim; + +if (resource >=RLIM_NLIMITS ) +return -EINVAL ; +if (copy_from_user (&new_rlim, rlim,sizeof (*rlim))) +return -EFAULT ; +return do_setrlimit (resource, &new_rlim); +} +/* * It would make sense to put struct rusage in the task_struct, * except that would make the task_struct be *really big*. After
Signature · 7 lines
1.6.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v18 65/80 c/r: [signal 3/4] pending signals (private, shared)
In reply to Oren LaadanThis patch adds checkpoint and restart of pending signals queues:
struct sigpending, both per-task t->sigpending and shared (per- thread-group) t->signal->shared_sigpending.
To checkpoint pending signals (private/shared) we first detach the signal queue (and copy the mask) to a separate struct sigpending. This separate structure can be iterated through without locking.
Once the state is saved, we re-attaches (prepends) the original signal queue back to the original struct sigpending.
Signals that arrive(d) in the meantime will be suitably queued after these (for real-time signals). Repeated non-realtime signals will not be queued because they will already be marked in the pending mask, that remains as is. This is the expected behavior of non-realtime signals.
Changelog [v4]:
- Rename headerless struct ckpt_hdr_* to struct ckpt_*
Changelog [v3]:
- [Dan Smith] Sanity check for number of pending signals in buffer
Changelog [v2]:
- Validate si_errno from checkpoint image
Changelog [v1]:
- Fix compilation warnings
- [Louis Rilling] Remove SIGQUEUE_PREALLOC flag from queued signals
- [Louis Rilling] Fail if task has posix-timers or SI_TIMER signal
--- checkpoint/signal.c | 277 +++++++++++++++++++++++++++++++++++++++- include/linux/checkpoint_hdr.h | 23 ++++ 2 files changed, 298 insertions(+), 2 deletions(-)
checkpoint/signal.c +275 -2
@@ -167,12 +167,156 @@ int restore_obj_sighand(struct ckpt_ctx *ctx, int sighand_objref)* signal checkpoint/restart */ +static void fill_siginfo (struct ckpt_siginfo *si,siginfo_t *info) +{ + si->signo = info->si_signo; + si->_errno = info->si_errno; + si->code = info->si_code; + +/* TODO: convert info->si_uid to uid_objref */ + +switch (info->si_code & __SI_MASK) { +case __SI_TIMER: + si->pid = info->si_tid; + si->uid = info->si_overrun; + si->sigval_int = info->si_int; + si->utime = info->si_sys_private; +break ; +case __SI_POLL: + si->pid = info->si_band; + si->sigval_int = info->si_fd; +break ; +case __SI_FAULT: + si->sigval_ptr = (unsigned long ) info->si_addr; +#ifdef __ARCH_SI_TRAPNO + si->sigval_int = info->si_trapno; +#endif +break ; +case __SI_CHLD: + si->pid = info->si_pid; + si->uid = info->si_uid; + si->sigval_int = info->si_status; + si->stime = info->si_stime; + si->utime = info->si_utime; +break ; +case __SI_KILL: +case __SI_RT: +case __SI_MESGQ: + si->pid = info->si_pid; + si->uid = info->si_uid; + si->sigval_ptr = (unsigned long ) info->si_ptr; +break ; +default : +BUG (); + } +} + +static int load_siginfo (siginfo_t *info,struct ckpt_siginfo *si) +{ +if (!valid_signal (si->signo)) +return -EINVAL ; +if (!ckpt_validate_errno (si->_errno)) +return -EINVAL ; + + info->si_signo = si->signo; + info->si_errno = si->_errno; + info->si_code = si->code; + +/* TODO: validate remaining signal fields */ + +switch (info->si_code & __SI_MASK) { +case __SI_TIMER: + info->si_tid = si->pid; + info->si_overrun = si->uid; + info->si_int = si->sigval_int; + info->si_sys_private = si->utime; +break ; +case __SI_POLL: + info->si_band = si->pid; + info->si_fd = si->sigval_int; +break ; +case __SI_FAULT: + info->si_addr = (void __user *) (unsigned long ) si->sigval_ptr; +#ifdef __ARCH_SI_TRAPNO + info->si_trapno = si->sigval_int; +#endif +break ; +case __SI_CHLD: + info->si_pid = si->pid; + info->si_uid = si->uid; + info->si_status = si->sigval_int; + info->si_stime = si->stime; + info->si_utime = si->utime; +break ; +case __SI_KILL: +case __SI_RT: +case __SI_MESGQ: + info->si_pid = si->pid; + info->si_uid = si->uid; + info->si_ptr = (void __user *) (unsigned long ) si->sigval_ptr; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +/* +* To checkpoint pending signals (private/shared) the caller moves the +* signal queue (and copies the mask) to a separate struct sigpending, +* therefore we can iterate through it without locking. +* After we return, the caller re-attaches (prepends) the original +* signal queue to the original struct sigpending. Thus, signals that +* arrive(d) in the meantime will be suitably queued after these. +* Finally, repeated non-realtime signals will not be queued because +* they will already be marked in the pending mask, that remains as is. +* This is the expected behavior of non-realtime signals. +*/ +static int checkpoint_sigpending (struct ckpt_ctx *ctx, +struct sigpending *pending) +{ +struct ckpt_hdr_sigpending *h; +struct ckpt_siginfo *si; +struct sigqueue *q; +int nr_pending =0 ; +int ret; + +list_for_each_entry (q, &pending->list, list) { +/* TODO: remove after adding support for posix-timers */ +if ((q->info.si_code & __SI_MASK) == __SI_TIMER) { +ckpt_write_err (ctx,"TE" ,"signal SI_TIMER" , -ENOTSUPP ); +return -ENOTSUPP ; + } + nr_pending++; + } + + h =ckpt_hdr_get_type (ctx, nr_pending *sizeof (*si) +sizeof (*h), +CKPT_HDR_SIGPENDING ); +if (!h) +return -ENOMEM ; + + h->nr_pending = nr_pending; +fill_sigset (&h->signal, &pending->signal); + + si = h->siginfo; +list_for_each_entry (q, &pending->list, list) +fill_siginfo (si++, &q->info); + + ret =ckpt_write_obj (ctx, &h->h); +ckpt_hdr_put (ctx, h); + +return ret; +} +static int checkpoint_signal (struct ckpt_ctx *ctx,struct task_struct *t) {struct ckpt_hdr_signal *h;struct signal_struct *signal; +struct sigpending shared_pending;struct rlimit *rlim; -int ret; +unsigned long flags; +int i, ret; h =ckpt_hdr_get_type (ctx,sizeof (*h),CKPT_HDR_SIGNAL );if (!h)
@@ -181,13 +325,45 @@ static int checkpoint_signal(struct ckpt_ctx *ctx, struct task_struct *t) signal = t->signal; rlim = signal->rlim; +INIT_LIST_HEAD (&shared_pending.list); + +/* temporarily borrow signal queue - see chekcpoint_sigpending() */ +if (!lock_task_sighand (t, &flags)) { +pr_warning ("c/r: [%d] without sighand\n" ,task_pid_vnr (t)); + ret = -EBUSY ; + goto out; + } + +/* TODO: remove after adding support for posix-timers */ +if (!list_empty (&signal->posix_timers)) { +ckpt_write_err (ctx,"TEP" ,"posix-timers\n" , -ENOTSUPP , signal); +unlock_task_sighand (t, &flags); + ret = -ENOTSUPP ; + goto out; + } + +list_splice_init (&signal->shared_pending.list, &shared_pending.list); + shared_pending.signal = signal->shared_pending.signal; +/* rlimit */ for (i =0 ; i <RLIM_NLIMITS ; i++) { h->rlim[i].rlim_cur = rlim[i].rlim_cur; h->rlim[i].rlim_max = rlim[i].rlim_max; } +unlock_task_sighand (t, &flags); ret =ckpt_write_obj (ctx, &h->h); +if (!ret) + ret =checkpoint_sigpending (ctx, &shared_pending); + +/* return the borrowed queue */ +if (!lock_task_sighand (t, &flags)) { +pr_warning ("c/r: [%d] sighand disappeared\n" ,task_pid_vnr (t)); + goto out; + } +list_splice (&shared_pending.list, &signal->shared_pending.list); +unlock_task_sighand (t, &flags); + out:ckpt_hdr_put (ctx, h);return ret; }
@@ -198,9 +374,55 @@ int checkpoint_obj_signal(struct ckpt_ctx *ctx, struct task_struct *t)return checkpoint_signal (ctx, t); } +static int restore_sigpending (struct ckpt_ctx *ctx,struct sigpending *pending) +{ +struct ckpt_hdr_sigpending *h; +struct ckpt_siginfo *si; +struct sigqueue *q; +int ret =0 ; + + h =ckpt_read_buf_type (ctx,0 ,CKPT_HDR_SIGPENDING ); +if (IS_ERR (h)) +return PTR_ERR (h); + +if (h->h.len != h->nr_pending *sizeof (*si) +sizeof (*h)) { + ret = -EINVAL ; + goto out; + } + +INIT_LIST_HEAD (&pending->list); +load_sigset (&pending->signal, &h->signal); + + si = h->siginfo; +while (h->nr_pending--) { + q =sigqueue_alloc (); +if (!q) { + ret = -ENOMEM ; +break ; + } + + ret =load_siginfo (&q->info, si++); +if (ret <0 ) { +sigqueue_free (q); +break ; + } + + q->flags &= ~SIGQUEUE_PREALLOC ; +list_add_tail (&pending->list, &q->list); + } + +if (ret <0 ) +flush_sigqueue (pending); + out: +ckpt_hdr_put (ctx, h); +return ret; +} +static int restore_signal (struct ckpt_ctx *ctx) {struct ckpt_hdr_signal *h; +struct sigpending new_pending; +struct sigpending *pending;struct rlimit rlim;int i, ret;
@@ -214,8 +436,19 @@ static int restore_signal(struct ckpt_ctx *ctx) rlim.rlim_max = h->rlim[i].rlim_max; ret =do_setrlimit (i, &rlim);if (ret <0 ) -break ; + goto out; } + + ret =restore_sigpending (ctx, &new_pending); +if (ret <0 ) + goto out; + +spin_lock_irq (¤t->sighand->siglock); + pending = ¤t->signal->shared_pending; +flush_sigqueue (pending); + pending->signal = new_pending.signal; +list_splice_init (&new_pending.list, &pending->list); +spin_unlock_irq (¤t->sighand->siglock); out:ckpt_hdr_put (ctx, h);return ret;
@@ -251,8 +484,34 @@ int restore_obj_signal(struct ckpt_ctx *ctx, int signal_objref)int checkpoint_task_signal (struct ckpt_ctx *ctx,struct task_struct *t) {struct ckpt_hdr_signal_task *h; +struct sigpending pending; +unsigned long flags;int ret; +INIT_LIST_HEAD (&pending.list); + +/* temporarily borrow signal queue - see chekcpoint_sigpending() */ +if (!lock_task_sighand (t, &flags)) { +ckpt_write_err (ctx,"TE" ,"signand missing" , -EBUSY ); +return -EBUSY ; + } +list_splice_init (&t->pending.list, &pending.list); + pending.signal = t->pending.signal; +unlock_task_sighand (t, &flags); + + ret =checkpoint_sigpending (ctx, &pending); + +/* re-attach the borrowed queue */ +if (!lock_task_sighand (t, &flags)) { +ckpt_write_err (ctx,"TE" ,"signand missing" , -EBUSY ); +return -EBUSY ; + } +list_splice (&pending.list, &t->pending.list); +unlock_task_sighand (t, &flags); + +if (ret <0 ) +return ret; + h =ckpt_hdr_get_type (ctx,sizeof (*h),CKPT_HDR_SIGNAL_TASK );if (!h)return -ENOMEM ;
@@ -267,7 +526,21 @@ int checkpoint_task_signal(struct ckpt_ctx *ctx, struct task_struct *t)int restore_task_signal (struct ckpt_ctx *ctx) {struct ckpt_hdr_signal_task *h; +struct sigpending new_pending; +struct sigpending *pending;sigset_t blocked; +int ret; + + ret =restore_sigpending (ctx, &new_pending); +if (ret <0 ) +return ret; + +spin_lock_irq (¤t->sighand->siglock); + pending = ¤t->pending; +flush_sigqueue (pending); + pending->signal = new_pending.signal; +list_splice_init (&new_pending.list, &pending->list); +spin_unlock_irq (¤t->sighand->siglock); h =ckpt_read_obj_type (ctx,sizeof (*h),CKPT_HDR_SIGNAL_TASK );if (IS_ERR (h))
include/linux/checkpoint_hdr.h +23 -0
@@ -90,6 +90,7 @@ enum {CKPT_HDR_SIGHAND =601 ,CKPT_HDR_SIGNAL ,CKPT_HDR_SIGNAL_TASK , +CKPT_HDR_SIGPENDING , CKPT_HDR_TAIL = 9001,
@@ -442,6 +443,28 @@ struct ckpt_hdr_sighand {struct ckpt_sigaction action[0 ]; } __attribute__((aligned(8))); +#ifndef HAVE_ARCH_SIGINFO_T +struct ckpt_siginfo { +__u32 signo; +__u32 _errno; +__u32 code; + +__u32 pid; +__s32 uid; +__u32 sigval_int; +__u64 sigval_ptr; +__u64 utime; +__u64 stime; +} __attribute__((aligned (8 ))); +#endif + +struct ckpt_hdr_sigpending { +struct ckpt_hdr h; +__u32 nr_pending; +struct ckpt_sigset signal; +struct ckpt_siginfo siginfo[0 ]; +} __attribute__((aligned (8 ))); +struct ckpt_rlimit {__u64 rlim_cur;__u64 rlim_max;
Signature · 7 lines
1.6.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v18 66/80 c/r: [signal 4/4] support for real/virt/prof itimers
In reply to Oren LaadanThis patch adds support for real/virt/prof itimers. Expiry and the interval values are both saved in nanoseconds.
Changelog[v1]:
- [Louis Rilling] Fix saving of signal->it_real_incr if not expired
- Fix restoring of signal->it_real_incr if expire is zero
- Save virt/prof expire relative to process accumulated time
--- checkpoint/signal.c | 86 ++++++++++++++++++++++++++++++++++++++++ include/linux/checkpoint_hdr.h | 6 +++ include/linux/posix-timers.h | 9 ++++ kernel/posix-cpu-timers.c | 9 ---- 4 files changed, 101 insertions(+), 9 deletions(-)
checkpoint/signal.c +86 -0
@@ -15,6 +15,8 @@#include <linux/signal.h> #include <linux/errno.h> #include <linux/resource.h> +#include <linux/timer.h> +#include <linux/posix-timers.h> #include <linux/checkpoint.h> #include <linux/checkpoint_hdr.h>
@@ -315,6 +317,8 @@ static int checkpoint_signal(struct ckpt_ctx *ctx, struct task_struct *t)struct signal_struct *signal;struct sigpending shared_pending;struct rlimit *rlim; +struct timeval tval; +cputime_t cputime;unsigned long flags;int i, ret;
@@ -350,6 +354,50 @@ static int checkpoint_signal(struct ckpt_ctx *ctx, struct task_struct *t) h->rlim[i].rlim_cur = rlim[i].rlim_cur; h->rlim[i].rlim_max = rlim[i].rlim_max; } + +/* real/virt/prof itimers */ +if (hrtimer_active (&signal->real_timer)) { +/* For an active timer compute the time delta */ +ktime_t delta =hrtimer_get_remaining (&signal->real_timer); +/* +* If the timer expired after the the test above, then +* set the expire to the minimum possible (because by +* now the pending signal have been saved already, but +* the signal from this very expiry won't be sent before +* we release t->sighand->siglock). +*/ +ckpt_debug ("active ! %lld\n" , delta.tv64); +if (delta.tv64 <=0 ) + delta.tv64 =NSEC_PER_USEC ; + h->it_real_value =ktime_to_ns (delta); + }else { +/* +* Timer is inactive; if @it_real_incr is 0 the timer +* will not be re-armed. Beacuse we hold siglock, if +* @it_real_incr > 0, the timer must have just expired +* but not yet re-armed, and we have a SIGALRM pending +* - that will trigger timer re-arm after restart. +*/ + h->it_real_value =0 ; + } + h->it_real_incr =ktime_to_ns (signal->it_real_incr); + + cputime = signal->it_virt_expires; +if (!cputime_eq (cputime, cputime_zero)) + cputime =cputime_sub (signal->it_virt_expires,virt_ticks (t)); +cputime_to_timeval (cputime, &tval); + h->it_virt_value =timeval_to_ns (&tval); +cputime_to_timeval (signal->it_virt_incr, &tval); + h->it_virt_incr =timeval_to_ns (&tval); + + cputime = signal->it_prof_expires; +if (!cputime_eq (cputime, cputime_zero)) + cputime =cputime_sub (signal->it_prof_expires,prof_ticks (t)); +cputime_to_timeval (cputime, &tval); + h->it_prof_value =timeval_to_ns (&tval); +cputime_to_timeval (signal->it_prof_incr, &tval); + h->it_prof_incr =timeval_to_ns (&tval); +unlock_task_sighand (t, &flags); ret =ckpt_write_obj (ctx, &h->h);
@@ -423,6 +471,7 @@ static int restore_signal(struct ckpt_ctx *ctx)struct ckpt_hdr_signal *h;struct sigpending new_pending;struct sigpending *pending; +struct itimerval itimer;struct rlimit rlim;int i, ret;
@@ -443,12 +492,49 @@ static int restore_signal(struct ckpt_ctx *ctx)if (ret <0 ) goto out; +/* +* Reset real/virt/prof itimer (in case they were set), to +* prevent unwanted signals after flushing current signals +* and before restoring original real/virt/prof itimer. +*/ + itimer.it_value = (struct timeval ) { .tv_sec =0 , .tv_usec =0 }; + itimer.it_interval = (struct timeval ) { .tv_sec =0 , .tv_usec =0 }; +do_setitimer (ITIMER_REAL , &itimer,NULL ); +do_setitimer (ITIMER_VIRTUAL , &itimer,NULL ); +do_setitimer (ITIMER_PROF , &itimer,NULL ); +spin_lock_irq (¤t->sighand->siglock); pending = ¤t->signal->shared_pending;flush_sigqueue (pending); pending->signal = new_pending.signal;list_splice_init (&new_pending.list, &pending->list);spin_unlock_irq (¤t->sighand->siglock); + +/* real/virt/prof itimers */ + itimer.it_value =ns_to_timeval (h->it_real_value); + itimer.it_interval =ns_to_timeval (h->it_real_incr); + ret =do_setitimer (ITIMER_REAL , &itimer,NULL ); +if (ret <0 ) + goto out; +/* +* If expire is 0 but incr > 0 then we have a SIGALRM pending. +* It should re-arm the timer when handled. But do_setitimer() +* above already ignored @it_real_incr because @it_real_value +* that was zero. So we set it manually. (This is safe against +* malicious input, because in the worst case will generate an +* unexpected SIGALRM to this process). +*/ +if (!h->it_real_value && h->it_real_incr) + current->signal->it_real_incr =ns_to_ktime (h->it_real_incr); + + itimer.it_value =ns_to_timeval (h->it_virt_value); + itimer.it_interval =ns_to_timeval (h->it_virt_incr); + ret =do_setitimer (ITIMER_VIRTUAL , &itimer,NULL ); +if (ret <0 ) + goto out; + itimer.it_value =ns_to_timeval (h->it_prof_value); + itimer.it_interval =ns_to_timeval (h->it_prof_incr); + ret =do_setitimer (ITIMER_PROF , &itimer,NULL ); out:ckpt_hdr_put (ctx, h);return ret;
include/linux/checkpoint_hdr.h +6 -0
@@ -482,6 +482,12 @@ struct ckpt_rlimit {struct ckpt_hdr_signal {struct ckpt_hdr h;struct ckpt_rlimit rlim[CKPT_RLIM_NLIMITS ]; +__u64 it_real_value; +__u64 it_real_incr; +__u64 it_virt_value; +__u64 it_virt_incr; +__u64 it_prof_value; +__u64 it_prof_incr; } __attribute__((aligned (8 )));struct ckpt_hdr_signal_task {
include/linux/posix-timers.h +9 -0
@@ -125,4 +125,13 @@ void update_rlimit_cpu(unsigned long rlim_new);int invalid_clockid (const clockid_t which_clock); +static inline cputime_t prof_ticks (struct task_struct *p) +{ +return cputime_add (p->utime, p->stime); +} +static inline cputime_t virt_ticks (struct task_struct *p) +{ +return p->utime; +} +#endif
kernel/posix-cpu-timers.c +0 -9
@@ -167,15 +167,6 @@ static void bump_cpu_timer(struct k_itimer *timer, } } -static inline cputime_t prof_ticks (struct task_struct *p) -{ -return cputime_add (p->utime, p->stime); -} -static inline cputime_t virt_ticks (struct task_struct *p) -{ -return p->utime; -} -int posix_cpu_clock_getres (const clockid_t which_clock,struct timespec *tp) {int error =check_clock (which_clock);
Signature · 7 lines
1.6.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v18 67/80 Expose may_setuid() in user.h and add may_setgid() (v2)
In reply to Oren LaadanFrom: Dan Smith <[email protected]>
Make these helpers available to others.
Changes in v2:
- Avoid checking the groupinfo in ctx->realcred against the current in may_setgid()
--- include/linux/user.h | 9 +++++++++ kernel/user.c | 13 ++++++++++++- 2 files changed, 21 insertions(+), 1 deletions(-)
include/linux/user.h +9 -0
@@ -1 +1,10 @@ +#ifndef _LINUX_USER_H +#define _LINUX_USER_H +#include <asm/user.h> +#include <linux/sched.h> + +extern int may_setuid (struct user_namespace *ns,uid_t uid); +extern int may_setgid (gid_t gid); + +#endif
kernel/user.c +12 -1
@@ -604,7 +604,7 @@ int checkpoint_user(struct ckpt_ctx *ctx, void *ptr)return do_checkpoint_user (ctx, (struct user_struct *) ptr); } -static int may_setuid (struct user_namespace *ns,uid_t uid) +int may_setuid (struct user_namespace *ns,uid_t uid) {/* * this next check will one day become
@@ -631,6 +631,17 @@ static int may_setuid(struct user_namespace *ns, uid_t uid)return 0 ; } +int may_setgid (gid_t gid) +{ +if (capable (CAP_SETGID )) +return 1 ; + +if (in_egroup_p (gid)) +return 1 ; + +return 0 ; +} +static struct user_struct *do_restore_user (struct ckpt_ctx *ctx) {struct user_struct *u;
Signature · 7 lines
1.6.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v18 68/80 Add common socket helpers to unify the security hooks
In reply to Oren LaadanFrom: Dan Smith <[email protected]>
This moves the meat out of the bind(), getsockname(), and getpeername() syscalls into helper functions that performs security_socket_bind() and then the sock->ops->call(). This allows a unification of this behavior between the syscalls and the pending socket restart logic.
--- include/net/sock.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ net/socket.c | 29 ++++++----------------------- 2 files changed, 54 insertions(+), 23 deletions(-)
include/net/sock.h +48 -0
@@ -1578,6 +1578,54 @@ extern void sock_enable_timestamp(struct sock *sk, int flag);extern int sock_get_timestamp (struct sock *,struct timeval __user *);extern int sock_get_timestampns (struct sock *,struct timespec __user *); +/* bind() helper shared between any callers needing to perform a bind on +* behalf of userspace (syscall and restart) with the security hooks. +*/ +static inline int sock_bind (struct socket *sock, +struct sockaddr *addr, +int addr_len) +{ +int err; + + err =security_socket_bind (sock, addr, addr_len); +if (err) +return err; +else +return sock->ops->bind (sock, addr, addr_len); +} + +/* getname() helper shared between any callers needing to perform a getname on +* behalf of userspace (syscall and restart) with the security hooks. +*/ +static inline int sock_getname (struct socket *sock, +struct sockaddr *addr, +int *addr_len) +{ +int err; + + err =security_socket_getsockname (sock); +if (err) +return err; +else +return sock->ops->getname (sock, addr, addr_len,0 ); +} + +/* getpeer() helper shared between any callers needing to perform a getpeer on +* behalf of userspace (syscall and restart) with the security hooks. +*/ +static inline int sock_getpeer (struct socket *sock, +struct sockaddr *addr, +int *addr_len) +{ +int err; + + err =security_socket_getpeername (sock); +if (err) +return err; +else +return sock->ops->getname (sock, addr, addr_len,1 ); +} +/* * Enable debug/info messages */
net/socket.c +6 -23
@@ -1414,15 +1414,10 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen) sock =sockfd_lookup_light (fd, &err, &fput_needed);if (sock) { err =move_addr_to_kernel (umyaddr, addrlen, (struct sockaddr *)&address); -if (err >=0 ) { - err =security_socket_bind (sock, - (struct sockaddr *)&address, - addrlen); -if (!err) - err = sock->ops->bind (sock, - (struct sockaddr *) - &address, addrlen); - } +if (err >=0 ) + err =sock_bind (sock, + (struct sockaddr *)&address, + addrlen);fput_light (sock->file, fput_needed); }return err;
@@ -1610,11 +1605,7 @@ SYSCALL_DEFINE3(getsockname, int, fd, struct sockaddr __user *, usockaddr,if (!sock) goto out; - err =security_socket_getsockname (sock); -if (err) - goto out_put; - - err = sock->ops->getname (sock, (struct sockaddr *)&address, &len,0 ); + err =sock_getname (sock, (struct sockaddr *)&address, &len);if (err) goto out_put; err =move_addr_to_user ((struct sockaddr *)&address, len, usockaddr, usockaddr_len);
@@ -1639,15 +1630,7 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr, sock =sockfd_lookup_light (fd, &err, &fput_needed);if (sock !=NULL ) { - err =security_socket_getpeername (sock); -if (err) { -fput_light (sock->file, fput_needed); -return err; - } - - err = - sock->ops->getname (sock, (struct sockaddr *)&address, &len, -1 ); + err =sock_getpeer (sock, (struct sockaddr *)&address, &len);if (!err) err =move_addr_to_user ((struct sockaddr *)&address, len, usockaddr, usockaddr_len);
Signature · 7 lines
1.6.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v18 69/80 c/r: introduce checkpoint/restore methods to struct proto_ops
In reply to Oren LaadanThis adds new 'proto_ops' function for checkpointing and restoring sockets. This allows the checkpoint/restart code to compile nicely when, e.g., AF_UNIX sockets are selected as a module.
It also adds a function 'collecting' a socket for leak-detection during full-container checkpoint. This is useful for those sockets that hold references to other "collectable" objects. Two examples are AF_UNIX buffers which reference the socket of origin, and sockets that have file descriptors in-transit.
--- include/linux/net.h | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)
include/linux/net.h +9 -0
@@ -147,6 +147,9 @@ struct sockaddr;struct msghdr ;struct module ; +struct ckpt_ctx ; +struct ckpt_hdr_socket ; +struct proto_ops {int family;struct module *owner;
@@ -191,6 +194,12 @@ struct proto_ops { int offset, size_t size, int flags);ssize_t (*splice_read)(struct socket *sock,loff_t *ppos,struct pipe_inode_info *pipe,size_t len,unsigned int flags); +int (*checkpoint)(struct ckpt_ctx *ctx, +struct socket *sock); +int (*collect)(struct ckpt_ctx *ctx, +struct socket *sock); +int (*restore)(struct ckpt_ctx *ctx,struct socket *sock, +struct ckpt_hdr_socket *h); };struct net_proto_family {
Signature · 7 lines
1.6.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v18 70/80 c/r: Add AF_UNIX support (v12)
In reply to Oren LaadanFrom: Dan Smith <[email protected]>
This patch adds basic checkpoint/restart support for AF_UNIX sockets. It has been tested with a single and multiple processes, and with data inflight at the time of checkpoint. It supports socketpair()s, path-based, and abstract sockets.
Changes in v12:
- Collect sockets for leak-detection
- Adjust socket reference count during leak detection phase
Changes in v11:
- Create a struct socket for orphan socket during checkpoint
- Make sockets proper objhash objects and use checkpoint_obj() on them
- Rename headerless struct ckpt_hdr_* to struct ckpt_*
- Remove struct timeval from socket header
- Save and restore UNIX socket peer credentials
- Set socket flags on restore using sock_setsockopt() where possible
- Fail on the TIMESTAMPING_* flags for the moment (with a TODO)
- Remove other explicit flag checks that are no longer copied blindly
- Changed functions/variables names to follow existing conventions
- Use proto_ops->{checkpoint,restart} methods for af_unix
- Cleanup sock_file_restore()/sock_file_checkpoint()
- Make ckpt_hdr_socket be part of ckpt_hdr_file_socket
- Fold do_sock_file_checkpoint() into sock_file_checkpoint()
- Fold do_sock_file_restore() into sock_file_restore()
- Move sock_file_{checkpoint,restore} to net/checkpoint.c
- Properly define sock_file_{checkpoint,restore} in header file
- sock_file_restore() now calls restore_file_common()
Changes in v10:
- Moved header structure definitions back to checkpoint_hdr.h
- Moved AF_UNIX checkpoint/restart code to net/unix/checkpoint.c
- Make sock_unix_*() functions only compile if CONFIG_UNIX=y
- Add TODO for CONFIG_UNIX=m case
Changes in v9:
- Fix double-free of skb's in the list and target holding queue in the error path of sock_copy_buffers()
- Adjust use of ckpt_read_string() to match new signature
Changes in v8:
- Fix stale dev_alloc_skb() from before the conversion to skb_clone()
- Fix a couple of broken error paths
- Fix memory leak of kvec.iov_base on successful return from sendmsg()
- Fix condition for deciding when to run sock_cptrst_verify()
- Fix buffer queue copy algorithm to hold the lock during walk(s)
- Log the errno when either getname() or getpeer() fails
- Add comments about ancillary messages in the UNIX queue
- Add TODO comments for credential restore and flags via setsockopt()
- Add TODO comment about strangely-connected dgram sockets and the use of sendmsg(peer)
Changes in v7:
- Fix failure to free iov_base in error path of sock_read_buffer()
- Change sock_read_buffer() to use _ckpt_read_obj_type() to get the header length and then use ckpt_kread() directly to read the payload
- Change sock_read_buffers() to sock_unix_read_buffers() and break out some common functionality to better accommodate the subsequent INET patch
- Generalize sock_unix_getnames() into sock_getnames() so INET can use it
- Change skb_morph() to skb_clone() which uses the more common path and still avoids the copy
- Add check to validate the socket type before creating socket on restore
- Comment the CAP_NET_ADMIN override in sock_read_buffer_hdr
- Strengthen the comment about priming the buffer limits
- Change the objhash functions to deny direct checkpoint of sockets and remove the reference counting function
- Change SOCKET_BUFFERS to SOCKET_QUEUE
- Change this,peer objrefs to signed integers
- Remove names from internal socket structures
- Fix handling of sock_copy_buffers() result
- Use ckpt_fill_fname() instead of d_path() for writing CWD
- Use sock_getname() and sock_getpeer() for proper security hookage
- Return -ENOSYS for unsupported socket families in checkpoint and restart
- Use sock_setsockopt() and sock_getsockopt() where possible to save and restore socket option values
- Check for SOCK_DESTROY flag in the global verify function because none of our supported socket types use it
- Check for SOCK_USE_WRITE_QUEUE in AF_UNIX restore function because that flag should not be used on such a socket
- Check socket state in UNIX restart path to validate the subset of valid values
Changes in v6:
- Moved the socket addresses to the per-type header
- Eliminated the HASCWD flag
- Remove use of ckpt_write_err() in restart paths
- Change the order in which buffers are read so that we can set the socket's limit equal to the size of the image's buffers (if appropriate) and then restore the original values afterwards.
- Use the ckpt_validate_errno() helper
- Add a check to make sure that we didn't restore a (UNIX) socket with any skb's in the send buffer
- Fix up sock_unix_join() to not leave addr uninitialized for socketpair
- Remove inclusion of checkpoint_hdr.h in the socket files
- Make sock_unix_write_cwd() use ckpt_write_string() and use the new ckpt_read_string() for reading the cwd
- Use the restored realcred credentials in sock_unix_join()
- Fix error path of the chdir_and_bind
- Change the algorithm for reloading the socket buffers to use sendmsg() on the socket's peer for better accounting
- For DGRAM sockets, check the backlog value against the system max to avoid letting a restart bypass the overloaded queue length
- Use sock_bind() instead of sock->ops->bind() to gain the security hook
- Change "restart" to "restore" in some of the function names
Changes in v5:
- Change laddr and raddr buffers in socket header to be long enough for INET6 addresses
- Place socket.c and sock.h function definitions inside #ifdef CONFIG_CHECKPOINT
- Add explicit check in sock_unix_makeaddr() to refuse if the checkpoint image specifies an addr length of 0
- Split sock_unix_restart() into a few pieces to facilitate:
- Changed behavior of the unix restore code so that unlinked LISTEN sockets don't do a bind()...unlink()
- Save the base path of a bound socket's path so that we can chdir() to the base before bind() if it is a relative path
- Call bind() for any socket that is not established but has a non-zero-length local address
- Enforce the current sysctl limit on socket buffer size during restart unless the user holds CAP_NET_ADMIN
- Unlink a path-based socket before calling bind()
Changes in v4:
- Changed the signdness of rcvlowat, rcvtimeo, sndtimeo, and backlog to match their struct sock definitions. This should avoid issues with sign extension.
- Add a sock_cptrst_verify() function to be run at restore time to validate several of the values in the checkpoint image against limits, flag masks, etc.
- Write an error string with ctk_write_err() in the obscure cases
- Don't write socket buffers for listen sockets
- Sanity check address lengths before we agree to allocate memory
- Check the result of inserting the peer object in the objhash on restart
- Check return value of sock_cptrst() on restart
- Change logic in remote getname() phase of checkpoint to not fail for closed (et al) sockets
- Eliminate the memory copy while reading socket buffers on restart
Changes in v3:
- Move sock_file_checkpoint() above sock_file_restore()
- Change __sock_file_*() functions to do_sock_file_*()
- Adjust some of the struct cr_hdr_socket alignment
- Improve the sock_copy_buffers() algorithm to avoid locking the source queue for the entire operation
- Fix alignment in the socket header struct(s)
- Move the per-protocol structure (ckpt_hdr_socket_un) out of the common socket header and read/write it separately
- Fix missing call to sock_cptrst() in restore path
- Break out the socket joining into another function
- Fix failure to restore the socket address thus fixing getname()
- Check the state values on restart
- Fix case of state being TCP_CLOSE, which allows dgram sockets to be properly connected (if appropriate) to their peer and maintain the sockaddr for getname() operation
- Fix restoring a listening socket that has been unlink()'d
- Fix checkpointing sockets with an in-flight FD-passing SKB. Fail with EBUSY.
- Fix checkpointing listening sockets with an unaccepted connection. Fail with EBUSY.
- Changed 'un' to 'unix' in function and structure names
Changes in v2:
- Change GFP_KERNEL to GFP_ATOMIC in sock_copy_buffers() (this seems to be rather common in other uses of skb_copy())
- Move the ckpt_hdr_socket structure definition to linux/socket.h
- Fix whitespace issue
- Move sock_file_checkpoint() to net/socket.c for symmetry
--- checkpoint/files.c | 7 + checkpoint/objhash.c | 69 ++++ include/linux/checkpoint.h | 7 + include/linux/checkpoint_hdr.h | 87 +++++ include/linux/net.h | 2 + include/net/af_unix.h | 14 + include/net/sock.h | 12 + net/Makefile | 2 + net/checkpoint.c | 752 ++++++++++++++++++++++++++++++++++++++++ net/socket.c | 6 +- net/unix/Makefile | 1 + net/unix/af_unix.c | 9 + net/unix/checkpoint.c | 634 +++++++++++++++++++++++++++++++++ 13 files changed, 1601 insertions(+), 1 deletions(-) create mode 100644 net/checkpoint.c create mode 100644 net/unix/checkpoint.c
checkpoint/files.c +7 -0
@@ -22,6 +22,7 @@#include <linux/deferqueue.h> #include <linux/checkpoint.h> #include <linux/checkpoint_hdr.h> +#include <net/sock.h> /**************************************************************************
@@ -591,6 +592,12 @@ static struct restore_file_ops restore_file_ops[] = { .file_type = CKPT_FILE_FIFO, .restore = fifo_file_restore, }, +/* socket */ + { + .file_name = "SOCKET", + .file_type = CKPT_FILE_SOCKET, + .restore = sock_file_restore, + }, };static struct file *do_restore_file (struct ckpt_ctx *ctx)
checkpoint/objhash.c +69 -0
99 lines not on this page · raw message
include/linux/checkpoint.h +7 -0
@@ -29,6 +29,7 @@#include <linux/checkpoint_types.h> #include <linux/checkpoint_hdr.h> #include <linux/err.h> +#include <net/sock.h> /* ckpt_ctx: kflags */ #define CKPT_CTX_CHECKPOINT_BIT 0
@@ -77,6 +78,12 @@ extern int ckpt_read_consume(struct ckpt_ctx *ctx, int len, int type);extern char *ckpt_fill_fname (struct path *path,struct path *root,char *buf,int *len); +/* socket functions */ +extern int ckpt_sock_getnames (struct ckpt_ctx *ctx, +struct socket *socket, +struct sockaddr *loc,unsigned *loc_len, +struct sockaddr *rem,unsigned *rem_len); +/* ckpt kflags */ #define ckpt_set_ctx_kflag (__ctx, __kflag) \ set_bit(__kflag##_BIT, &(__ctx)->kflags)
include/linux/checkpoint_hdr.h +87 -0
117 lines not on this page · raw message
include/linux/net.h +2 -0
@@ -232,6 +232,8 @@ extern int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t len);extern int sock_recvmsg (struct socket *sock,struct msghdr *msg,size_t size,int flags); +extern int sock_attach_fd (struct socket *sock,struct file *file, +int flags);extern int sock_map_fd (struct socket *sock,int flags);extern struct socket *sockfd_lookup (int fd,int *err);#define sockfd_put (sock) fput(sock->file)
include/net/af_unix.h +14 -0
@@ -68,4 +68,18 @@ static inline int unix_sysctl_register(struct net *net) { return 0; }static inline void unix_sysctl_unregister (struct net *net) {}#endif #endif + +#ifdef CONFIG_CHECKPOINT +struct ckpt_ctx ; +struct ckpt_hdr_socket ; +extern int unix_checkpoint (struct ckpt_ctx *ctx,struct socket *sock); +extern int unix_restore (struct ckpt_ctx *ctx,struct socket *sock, +struct ckpt_hdr_socket *h); +extern int unix_collect (struct ckpt_ctx *ctx,struct socket *sock); + +#else +#define unix_checkpoint NULL +#define unix_restore NULL +#endif /* CONFIG_CHECKPOINT */ +#endif
include/net/sock.h +12 -0
@@ -1646,4 +1646,16 @@ extern int sysctl_optmem_max;extern __u32 sysctl_wmem_default;extern __u32 sysctl_rmem_default; +#ifdef CONFIG_CHECKPOINT +/* Checkpoint/Restart Functions */ +struct ckpt_ctx ; +struct ckpt_hdr_file ; +extern int checkpoint_sock (struct ckpt_ctx *ctx,void *ptr); +extern void *restore_sock (struct ckpt_ctx *ctx); +extern int sock_file_checkpoint (struct ckpt_ctx *ctx,struct file *file); +extern struct file *sock_file_restore (struct ckpt_ctx *ctx, +struct ckpt_hdr_file *h); +extern int sock_file_collect (struct ckpt_ctx *ctx,struct file *file); +#endif +#endif /* _SOCK_H */
net/Makefile +2 -0
@@ -66,3 +66,5 @@ ifeq ($(CONFIG_NET),y) obj-$(CONFIG_SYSCTL) += sysctl_net.o endif obj-$(CONFIG_WIMAX) += wimax/ + +obj-$(CONFIG_CHECKPOINT) += checkpoint.o
net/checkpoint.c new file +752 -0
752 lines not on this page · raw message
net/socket.c +5 -1
@@ -140,6 +140,10 @@ static const struct file_operations socket_file_ops = { .sendpage = sock_sendpage, .splice_write = generic_splice_sendpage, .splice_read = sock_splice_read, +#ifdef CONFIG_CHECKPOINT + .checkpoint = sock_file_checkpoint, + .collect = sock_file_collect, +#endif };/*
@@ -368,7 +372,7 @@ static int sock_alloc_fd(struct file **filep, int flags)return fd; } -static int sock_attach_fd (struct socket *sock,struct file *file,int flags) +int sock_attach_fd (struct socket *sock,struct file *file,int flags) {struct dentry *dentry;struct qstr name = { .name ="" };
net/unix/Makefile +1 -0
@@ -6,3 +6,4 @@ obj-$(CONFIG_UNIX) += unix.o unix-y := af_unix.o garbage.o unix-$(CONFIG_SYSCTL) += sysctl_net_unix.o +unix-$(CONFIG_CHECKPOINT) += checkpoint.o
net/unix/af_unix.c +9 -0
@@ -523,6 +523,9 @@ static const struct proto_ops unix_stream_ops = { .recvmsg = unix_stream_recvmsg, .mmap = sock_no_mmap, .sendpage = sock_no_sendpage, + .checkpoint = unix_checkpoint, + .restore = unix_restore, + .collect = unix_collect, };static const struct proto_ops unix_dgram_ops = {
@@ -544,6 +547,9 @@ static const struct proto_ops unix_dgram_ops = { .recvmsg = unix_dgram_recvmsg, .mmap = sock_no_mmap, .sendpage = sock_no_sendpage, + .checkpoint = unix_checkpoint, + .restore = unix_restore, + .collect = unix_collect, };static const struct proto_ops unix_seqpacket_ops = {
@@ -565,6 +571,9 @@ static const struct proto_ops unix_seqpacket_ops = { .recvmsg = unix_dgram_recvmsg, .mmap = sock_no_mmap, .sendpage = sock_no_sendpage, + .checkpoint = unix_checkpoint, + .restore = unix_restore, + .collect = unix_collect, };static struct proto unix_proto = {
net/unix/checkpoint.c new file +634 -0
634 lines not on this page · raw message
Signature · 7 lines
1.6.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v18 71/80 c/r: [pty 1/2] allow allocation of desired pty slave
In reply to Oren LaadanDuring restart, we need to allocate pty slaves with the same identifiers as recorded during checkpoint. Modify the allocation code to allow an in-kernel caller to request a specific slave identifier.
For this, add a new field to task_struct - 'required_id'. It will hold the desired identifier when restoring a (master) pty.
The code in ptmx_open() will use this value only for tasks that try to open /dev/ptmx that are restarting (PF_RESTARTING), and if the value isn't CKPT_REQUIRED_NONE (-1).
--- drivers/char/pty.c | 65 +++++++++++++++++++++++++++++++++++++++++--- drivers/char/tty_io.c | 4 +- fs/devpts/inode.c | 13 +++++++-- include/linux/devpts_fs.h | 6 +++- include/linux/sched.h | 1 + include/linux/tty.h | 2 + 6 files changed, 80 insertions(+), 11 deletions(-)
drivers/char/pty.c +60 -5
@@ -612,9 +612,10 @@ static const struct tty_operations pty_unix98_ops = { };/** -* ptmx_open - open a unix 98 pty master +* __ptmx_open - open a unix 98 pty master * @inode: inode of device file * @filp: file pointer to tty +* @index: desired slave index * * Allocate a unix98 pty master device from the ptmx driver. *
@@ -623,16 +624,15 @@ static const struct tty_operations pty_unix98_ops = {* allocated_ptys_lock handles the list of free pty numbers */ -static int __ptmx_open (struct inode *inode,struct file *filp) +static int __ptmx_open (struct inode *inode,struct file *filp,int index) {struct tty_struct *tty;int retval; -int index;nonseekable_open (inode, filp);/* find a device that is not in use. */ - index =devpts_new_index (inode); + index =devpts_new_index (inode, index);if (index <0 )return index;
@@ -668,12 +668,66 @@ static int ptmx_open(struct inode *inode, struct file *filp) {int ret; +#ifdef CONFIG_CHECKPOINT +/* +* If current task is restarting, we skip the actual open. +* Instead, leave it up to the caller (restart code) to invoke +* __ptmx_open() with the desired pty index request. +* +* NOTE: this gives a half-baked file that has ptmx f_op but +* the tty (private_data) is NULL. It is the responsibility of +* the _caller_ to ensure proper initialization before +* allowing it to be used (ptmx_release() tolerates NULL tty). +*/ +if (current->flags &PF_RESTARTING ) +return 0 ; +#endif +lock_kernel (); - ret =__ptmx_open (inode, filp); + ret =__ptmx_open (inode, filp,UNSPECIFIED_PTY_INDEX );unlock_kernel ();return ret; } +static int ptmx_release (struct inode *inode,struct file *filp) +{ +#ifdef CONFIG_CHECKPOINT +/* +* It is possible for a restart to create a half-baked +* ptmx file - see ptmx_open(). In that case there is no +* tty (private_data) and nothing to do. +*/ +if (!filp->private_data) +return 0 ; +#endif + +return tty_release (inode, filp); +} + +struct file *pty_open_by_index (char *ptmxpath,int index) +{ +struct file *ptmxfile; +int ret; + +/* +* We need to pick a way to specify which devpts mountpoint to +* use. For now, we'll just use whatever /dev/ptmx points to. +*/ + ptmxfile =filp_open (ptmxpath,O_RDWR |O_NOCTTY ,0 ); +if (IS_ERR (ptmxfile)) +return ptmxfile; + +lock_kernel (); + ret =__ptmx_open (ptmxfile->f_dentry->d_inode, ptmxfile, index); +unlock_kernel (); +if (ret) { +fput (ptmxfile); +return ERR_PTR (ret); + } + +return ptmxfile; +} +static struct file_operations ptmx_fops;static void __init unix98_pty_init (void )
@@ -730,6 +784,7 @@ static void __init unix98_pty_init(void)/* Now create the /dev/ptmx special device */ tty_default_fops (&ptmx_fops); ptmx_fops.open = ptmx_open; + ptmx_fops.release = ptmx_release;cdev_init (&ptmx_cdev, &ptmx_fops); if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
drivers/char/tty_io.c +2 -2
@@ -142,7 +142,7 @@ ssize_t redirected_tty_write(struct file *, const char __user *, size_t, loff_t *);static unsigned int tty_poll (struct file *,poll_table *);static int tty_open (struct inode *,struct file *); -static int tty_release (struct inode *,struct file *); +int tty_release (struct inode *,struct file *);long tty_ioctl (struct file *file,unsigned int cmd,unsigned long arg);#ifdef CONFIG_COMPAT static long tty_compat_ioctl(struct file *file, unsigned int cmd,
@@ -1846,7 +1846,7 @@ static int tty_open(struct inode *inode, struct file *filp)* Takes bkl. See tty_release_dev */ -static int tty_release (struct inode *inode,struct file *filp) +int tty_release (struct inode *inode,struct file *filp) {lock_kernel ();tty_release_dev (filp);
fs/devpts/inode.c +10 -3
@@ -433,11 +433,11 @@ static struct file_system_type devpts_fs_type = {* to the System V naming convention */ -int devpts_new_index (struct inode *ptmx_inode) +int devpts_new_index (struct inode *ptmx_inode,int req_idx) {struct super_block *sb =pts_sb_from_inode (ptmx_inode);struct pts_fs_info *fsi =DEVPTS_SB (sb); -int index; +int index = req_idx;int ida_ret; retry:
@@ -445,7 +445,9 @@ retry:return -ENOMEM ;mutex_lock (&allocated_ptys_lock); - ida_ret =ida_get_new (&fsi->allocated_ptys, &index); +if (index ==UNSPECIFIED_PTY_INDEX ) + index =0 ; + ida_ret =ida_get_new_above (&fsi->allocated_ptys, index, &index);if (ida_ret <0 ) {mutex_unlock (&allocated_ptys_lock);if (ida_ret == -EAGAIN )
@@ -453,6 +455,11 @@ retry:return -EIO ; } +if (req_idx !=UNSPECIFIED_PTY_INDEX && index != req_idx) { +ida_remove (&fsi->allocated_ptys, index); +mutex_unlock (&allocated_ptys_lock); +return -EBUSY ; + }if (index >= pty_limit) {ida_remove (&fsi->allocated_ptys, index);mutex_unlock (&allocated_ptys_lock);
include/linux/devpts_fs.h +5 -1
@@ -15,9 +15,13 @@#include <linux/errno.h> +#define UNSPECIFIED_PTY_INDEX -1 +#ifdef CONFIG_UNIX98_PTYS -int devpts_new_index (struct inode *ptmx_inode); +struct file *pty_open_by_index (char *ptmxpath,int index); + +int devpts_new_index (struct inode *ptmx_inode,int req_idx);void devpts_kill_index (struct inode *ptmx_inode,int idx);/* mknod in devpts */ int devpts_pty_new (struct inode *ptmx_inode,struct tty_struct *tty);
include/linux/sched.h +1 -0
@@ -1482,6 +1482,7 @@ struct task_struct {#endif /* CONFIG_TRACING */ #ifdef CONFIG_CHECKPOINT struct ckpt_ctx *checkpoint_ctx; +unsigned long required_id;#endif };
include/linux/tty.h +2 -0
@@ -468,6 +468,8 @@ extern void tty_ldisc_begin(void);/* This last one is just for the tty layer internals and shouldn't be used elsewhere */ extern void tty_ldisc_enable (struct tty_struct *tty); +/* This one is for ptmx_close() */ +extern int tty_release (struct inode *inode,struct file *filp);/* n_tty.c */ extern struct tty_ldisc_ops tty_ldisc_N_TTY;
Signature · 7 lines
1.6.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v18 72/80 c/r: [pty 2/2] support for pseudo terminals
In reply to Oren LaadanThis patch adds support for checkpoint and restart of pseudo terminals (PTYs). Since PTYs are shared (pointed to by file, and signal), they are managed via objhash.
PTYs are master/slave pairs; The code arranges for the master to always be checkpointed first, followed by the slave. This is important since during restart both ends are created when restoring the master.
In this patch only UNIX98 style PTYs are supported.
Currently only PTYs that are referenced by open files are handled. Thus PTYs checkpoint starts with a file in tty_file_checkpoint(). It will first checkpoint the master and slave PTYs via tty_checkpoint(), and then complete the saving of the file descriptor. This means that in the image file, the order of objects is: master-tty, slave-tty, file-desc.
During restart, to restore the master side, we open the /dev/ptmx device and get a file handle. But at this point we don't know the designated objref for this file, because the file is due later on in the image stream. On the other hand, we can't just fput() the file because it will close the PTY too.
Instead, when we checkpoint the master PTY, we _reserve_ an objref for the file (which won't be further used in checkpoint). Then at restart, use it to insert the file to objhash.
TODO:
* Better sanitize input from checkpoint image on restore
* Check the locking when saving/restoring tty_struct state
* Echo position/buffer isn't saved (is it needed ?)
* Handle multiple devpts mounts (namespaces)
* Paths of ptmx and slaves are hard coded (/dev/ptmx, /dev/pts/...)
Changelog[v4]:
- Fix error path(s) in restore_tty_ldisc()
- Fix memory leak in restore_tty_ldisc()
Changelog[v3]:
- [Serge Hallyn] Set tty on error path
Changelog[v2]:
- Don't save/restore tty->{session,pgrp}
- Fix leak: drop file reference after ckpt_obj_insert()
- Move get_file() inside locked clause (fix race)
Changelog[v1]:
- Adjust include/asm/checkpoint_hdr.h for s390 architecture
- Add NCC to kernel constants header (ckpt_hdr_const)
- [Serge Hallyn] fix calculation of canon_datalen
--- arch/s390/include/asm/checkpoint_hdr.h | 11 + arch/x86/include/asm/checkpoint_hdr.h | 11 + checkpoint/checkpoint.c | 3 + checkpoint/files.c | 6 + checkpoint/objhash.c | 26 ++ checkpoint/restart.c | 6 + drivers/char/pty.c | 1 + drivers/char/tty_io.c | 499 ++++++++++++++++++++++++++++++++ include/linux/checkpoint.h | 4 + include/linux/checkpoint_hdr.h | 85 ++++++ include/linux/tty.h | 7 + 11 files changed, 659 insertions(+), 0 deletions(-)
arch/s390/include/asm/checkpoint_hdr.h +11 -0
@@ -83,13 +83,24 @@ struct ckpt_hdr_mm_context { };#define CKPT_ARCH_NSIG 64 +#define CKPT_TTY_NCC 8 + +/* arch dependent constants */ #ifdef __KERNEL__ +#include <asm/signal.h> #if CKPT_ARCH_NSIG != _SIGCONTEXT_NSIG#error CKPT_ARCH_NSIG size is wrong (asm/sigcontext.h and asm/checkpoint_hdr.h)#endif + +#include <linux/tty.h> +#if CKPT_TTY_NCC !=NCC +#error CKPT_TTY_NCC size is wrong per asm-generic/termios.h#endif +#endif /* __KERNEL__ */ + +struct ckpt_hdr_header_arch {struct ckpt_hdr h; };
arch/x86/include/asm/checkpoint_hdr.h +11 -0
@@ -48,14 +48,25 @@ enum { CKPT_HDR_MM_CONTEXT_LDT, }; +/* arch dependent constants */ #define CKPT_ARCH_NSIG 64 +#define CKPT_TTY_NCC 8 +#ifdef __KERNEL__ +#include <asm/signal.h> #if CKPT_ARCH_NSIG != _NSIG#error CKPT_ARCH_NSIG size is wrong per asm/signal.h and asm/checkpoint_hdr.h#endif + +#include <linux/tty.h> +#if CKPT_TTY_NCC !=NCC +#error CKPT_TTY_NCC size is wrong per asm-generic/termios.h#endif +#endif /* __KERNEL__ */ + +struct ckpt_hdr_header_arch {struct ckpt_hdr h;/* FIXME: add HAVE_HWFP */
checkpoint/checkpoint.c +3 -0
@@ -299,6 +299,9 @@ static void fill_kernel_const(struct ckpt_const *h) h->uts_domainname_len =sizeof (uts->domainname);/* rlimit */ h->rlimit_nlimits =RLIM_NLIMITS ; +/* tty */ + h->n_tty_buf_size =N_TTY_BUF_SIZE ; + h->tty_termios_ncc =NCC ; }/* write the checkpoint header */
checkpoint/files.c +6 -0
@@ -598,6 +598,12 @@ static struct restore_file_ops restore_file_ops[] = { .file_type = CKPT_FILE_SOCKET, .restore = sock_file_restore, }, +/* tty */ + { + .file_name = "TTY", + .file_type = CKPT_FILE_TTY, + .restore = tty_file_restore, + }, };static struct file *do_restore_file (struct ckpt_ctx *ctx)
checkpoint/objhash.c +26 -0
@@ -269,6 +269,22 @@ static int obj_sock_users(void *ptr)return atomic_read (&((struct sock *) ptr)->sk_refcnt); } +static int obj_tty_grab (void *ptr) +{ +tty_kref_get ((struct tty_struct *) ptr); +return 0 ; +} + +static void obj_tty_drop (void *ptr,int lastref) +{ +tty_kref_put ((struct tty_struct *) ptr); +} + +static int obj_tty_users (void *ptr) +{ +return atomic_read (&((struct tty_struct *) ptr)->kref.refcount); +} +static struct ckpt_obj_ops ckpt_obj_ops[] = {/* ignored object */ {
@@ -407,6 +423,16 @@ static struct ckpt_obj_ops ckpt_obj_ops[] = { .checkpoint = checkpoint_sock, .restore = restore_sock, }, +/* struct tty_struct */ + { + .obj_name = "TTY", + .obj_type = CKPT_OBJ_TTY, + .ref_drop = obj_tty_drop, + .ref_grab = obj_tty_grab, + .ref_users = obj_tty_users, + .checkpoint = checkpoint_tty, + .restore = restore_tty, + }, };
checkpoint/restart.c +6 -0
@@ -19,6 +19,7 @@#include <linux/freezer.h> #include <linux/magic.h> #include <linux/utsname.h> +#include <linux/termios.h> #include <asm/syscall.h> #include <linux/elf.h> #include <linux/deferqueue.h>
@@ -402,6 +403,11 @@ static int check_kernel_const(struct ckpt_const *h)/* rlimit */ if (h->rlimit_nlimits !=RLIM_NLIMITS )return -EINVAL ; +/* tty */ +if (h->n_tty_buf_size !=N_TTY_BUF_SIZE ) +return -EINVAL ; +if (h->tty_termios_ncc !=NCC ) +return -EINVAL ;return 0 ; }
drivers/char/pty.c +1 -0
@@ -15,6 +15,7 @@#include <linux/errno.h> #include <linux/interrupt.h> +#include <linux/file.h> #include <linux/tty.h> #include <linux/tty_flip.h> #include <linux/fcntl.h>
drivers/char/tty_io.c +499 -0
529 lines not on this page · raw message
include/linux/checkpoint.h +4 -0
@@ -266,6 +266,10 @@ extern int restore_obj_signal(struct ckpt_ctx *ctx, int signal_objref);extern int checkpoint_task_signal (struct ckpt_ctx *ctx,struct task_struct *t);extern int restore_task_signal (struct ckpt_ctx *ctx); +/* ttys */ +extern int checkpoint_tty (struct ckpt_ctx *ctx,void *ptr); +extern void *restore_tty (struct ckpt_ctx *ctx); +static inline int ckpt_validate_errno (int errno) {return (errno >=0 ) && (errno <MAX_ERRNO );
include/linux/checkpoint_hdr.h +85 -0
115 lines not on this page · raw message
include/linux/tty.h +7 -0
@@ -471,6 +471,13 @@ extern void tty_ldisc_enable(struct tty_struct *tty);/* This one is for ptmx_close() */ extern int tty_release (struct inode *inode,struct file *filp); +#ifdef CONFIG_CHECKPOINT +struct ckpt_ctx ; +struct ckpt_hdr_file ; +extern struct file *tty_file_restore (struct ckpt_ctx *ctx, +struct ckpt_hdr_file *ptr); +#endif +/* n_tty.c */ extern struct tty_ldisc_ops tty_ldisc_N_TTY;
Signature · 6 lines
1.6.0.4 -- To unsubscribe from this list: send the line "unsubscribe linux-api" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v18 73/80 c/r: correctly restore pgid
In reply to Oren LaadanThe main challenge with restoring the pgid of tasks is that the original "owner" (the process with that pid) might have exited already. I call these "ghost" pgids. 'mktree' does create these processes, but they then exit without participating in the restart.
To solve this, this patch introduces a RESTART_GHOST flag, used for "ghost" owners that are created only to pass their pgid to other tasks. ('mktree' now makes them call restart(2) instead of exiting).
When a "ghost" task calls restart(2), it will be placed on a wait queue until the restart completes and then exit. This guarantees that the pgid that it owns remains available for all (regular) restarting tasks for when they need it.
Regular tasks perform the restart as before, except that they also now restore their old pgrp, which is guaranteed to exist.
Changelog [v3]:
- Fix leak of ckpt_ctx when restoring "ghost" tasks
Changelog [v2]:
- Call change_pid() only if new pgrp differs from current one
Changelog [v1]:
- Verify that pgid owner is a thread-group-leader.
- Handle the case of pgid/sid == 0 using root's parent pid-ns
--- checkpoint/process.c | 97 +++++++++++++++++++++++++++ checkpoint/restart.c | 137 +++++++++++++++++++++++++++----------- checkpoint/sys.c | 3 +- include/linux/checkpoint.h | 11 +++- include/linux/checkpoint_hdr.h | 3 + include/linux/checkpoint_types.h | 6 +- 6 files changed, 214 insertions(+), 43 deletions(-)
checkpoint/process.c +97 -0
@@ -24,6 +24,57 @@#include <linux/syscalls.h> +pid_t ckpt_pid_nr (struct ckpt_ctx *ctx,struct pid *pid) +{ +return pid ?pid_nr_ns (pid, ctx->root_nsproxy->pid_ns) :CKPT_PID_NULL ; +} + +/* must be called with tasklist_lock or rcu_read_lock() held */ +struct pid *_ckpt_find_pgrp (struct ckpt_ctx *ctx,pid_t pgid) +{ +struct task_struct *p; +struct pid *pgrp; + +if (pgid ==0 ) { +/* +* At checkpoint the pgid owner lived in an ancestor +* pid-ns. The best we can do (sanely and safely) is +* to examine the parent of this restart's root: if in +* a distinct pid-ns, use its pgrp; otherwise fail. +*/ + p = ctx->root_task->real_parent; +if (p->nsproxy->pid_ns == current->nsproxy->pid_ns) +return NULL ; + pgrp =task_pgrp (p); + }else { +/* +* Find the owner process of this pgid (it must exist +* if pgrp exists). It must be a thread group leader. +*/ + pgrp =find_vpid (pgid); + p =pid_task (pgrp,PIDTYPE_PID ); +if (!p || !thread_group_leader (p)) +return NULL ; +/* +* The pgrp must "belong" to our restart tree (compare +* p->checkpoint_ctx to ours). This prevents malicious +* input from (guessing and) using unrelated pgrps. If +* the owner is dead, then it doesn't have a context, +* so instead compare against its (real) parent's. +*/ +if (p->exit_state ==EXIT_ZOMBIE ) + p = p->real_parent; +if (p->checkpoint_ctx != ctx) +return NULL ; + } + +if (task_session (current) !=task_session (p)) +return NULL ; + +return pgrp; +} + +#ifdef CONFIG_FUTEX static void save_task_robust_futex_list (struct ckpt_hdr_task *h,struct task_struct *t)
@@ -720,6 +771,49 @@ int restore_restart_block(struct ckpt_ctx *ctx)return ret; } +static int restore_task_pgid (struct ckpt_ctx *ctx) +{ +struct task_struct *task = current; +struct pid *pgrp; +pid_t pgid; +int ret; + +/* +* We enforce the following restrictions on restoring pgrp: +* 1) Only thread group leaders restore pgrp +* 2) Session leader cannot change own pgrp +* 3) Owner of pgrp must belong to same restart tree +* 4) Must have same session as other tasks in same pgrp +* 5) Change must pass setpgid security callback +* +* TODO - check if we need additional restrictions ? +*/ + +if (!thread_group_leader (task))/* (1) */ +return 0 ; + + pgid = ctx->pids_arr[ctx->active_pid].vpgid; + +if (pgid ==task_pgrp_vnr (task))/* nothing to do */ +return 0 ; + +if (task->signal->leader)/* (2) */ +return -EINVAL ; + + ret = -EINVAL ; + +write_lock_irq (&tasklist_lock); + pgrp =_ckpt_find_pgrp (ctx, pgid);/* (3) and (4) */ +if (pgrp &&task_pgrp (task) != pgrp) { + ret =security_task_setpgid (task, pgid);/* (5) */ +if (!ret) +change_pid (task,PIDTYPE_PGID , pgrp); + } +write_unlock_irq (&tasklist_lock); + +return ret; +} +/* pre_restore_task - prepare the task for restore */ static int pre_restore_task (struct ckpt_ctx *ctx) {
@@ -760,6 +854,9 @@ int restore_task(struct ckpt_ctx *ctx)if (ret) goto out; + ret =restore_task_pgid (ctx); +if (ret <0 ) + goto out; ret =restore_task_objs (ctx);ckpt_debug ("objs %d\n" , ret);if (ret <0 )
checkpoint/restart.c +99 -38
249 lines not on this page · raw message
checkpoint/sys.c +2 -1
@@ -238,6 +238,7 @@ static struct ckpt_ctx *ckpt_ctx_alloc(int fd, unsigned long uflags,INIT_LIST_HEAD (&ctx->pgarr_list);INIT_LIST_HEAD (&ctx->pgarr_pool);init_waitqueue_head (&ctx->waitq); +init_waitqueue_head (&ctx->ghostq); err = -EBADF ; ctx->file =fget (fd);
@@ -334,7 +335,7 @@ SYSCALL_DEFINE3(restart, pid_t, pid, int, fd, unsigned long, flags)if (IS_ERR (ctx))return PTR_ERR (ctx); - ret =do_restart (ctx, pid); + ret =do_restart (ctx, pid, flags);ckpt_ctx_put (ctx);return ret;
include/linux/checkpoint.h +9 -2
@@ -18,6 +18,7 @@/* restart user flags */ #define RESTART_TASKSELF 0x1#define RESTART_FROZEN 0x2 +#define RESTART_GHOST 0x4#ifdef __KERNEL__#ifdef CONFIG_CHECKPOINT
@@ -44,7 +45,10 @@/* ckpt_ctx: uflags */ #define CHECKPOINT_USER_FLAGS CHECKPOINT_SUBTREE -#define RESTART_USER_FLAGS (RESTART_TASKSELF | RESTART_FROZEN) +#define RESTART_USER_FLAGS \ + (RESTART_TASKSELF | \ + RESTART_FROZEN | \ + RESTART_GHOST)extern void exit_checkpoint (struct task_struct *tsk);
@@ -78,6 +82,9 @@ extern int ckpt_read_consume(struct ckpt_ctx *ctx, int len, int type);extern char *ckpt_fill_fname (struct path *path,struct path *root,char *buf,int *len); +/* pids */ +extern pid_t ckpt_pid_nr (struct ckpt_ctx *ctx,struct pid *pid); +/* socket functions */ extern int ckpt_sock_getnames(struct ckpt_ctx *ctx, struct socket *socket,
@@ -130,7 +137,7 @@ extern void ckpt_ctx_get(struct ckpt_ctx *ctx);extern void ckpt_ctx_put (struct ckpt_ctx *ctx);extern long do_checkpoint (struct ckpt_ctx *ctx,pid_t pid); -extern long do_restart (struct ckpt_ctx *ctx,pid_t pid); +extern long do_restart (struct ckpt_ctx *ctx,pid_t pid,unsigned long flags);/* task */ extern int ckpt_activate_next (struct ckpt_ctx *ctx);
include/linux/checkpoint_hdr.h +3 -0
@@ -215,6 +215,9 @@ struct ckpt_pids {__s32 vsid; } __attribute__((aligned(8))); +/* pids */ +#define CKPT_PID_NULL -1 +/* task data */ struct ckpt_hdr_task {struct ckpt_hdr h;
include/linux/checkpoint_types.h +4 -2
@@ -68,9 +68,11 @@ struct ckpt_ctx {/* [multi-process restart] */ struct ckpt_pids *pids_arr;/* array of all pids [restart] */ int nr_pids;/* size of pids array */ +atomic_t nr_total;/* total tasks count (with ghosts) */ int active_pid;/* (next) position in pids array */ -struct completion complete;/* container root and other tasks on */ -wait_queue_head_t waitq;/* start, end, and restart ordering */ +struct completion complete;/* completion for container root */ +wait_queue_head_t waitq;/* waitqueue for restarting tasks */ +wait_queue_head_t ghostq;/* waitqueue for ghost tasks */ struct cred *realcred, *ecred;/* tmp storage for cred at restart */ struct ckpt_stats stats;/* statistics */
Signature · 7 lines
1.6.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v18 74/80 c/r: support for controlling terminal and job control
In reply to Oren LaadanAdd checkpoint/restart of controlling terminal: current->signal->tty. This is only done for session leaders.
If the session leader belongs to the ancestor pid-ns, then checkpoint skips this tty; On restart, it will not be restored, and whatever tty is in place from parent pid-ns (at restart) will be inherited.
Chagnelog [v1]:
- Don't restore tty_old_pgrp it pgid is CKPT_PID_NULL
- Initialize pgrp to NULL in restore_signal
--- checkpoint/signal.c | 79 +++++++++++++++++++++++++++++++++++++++- drivers/char/tty_io.c | 33 +++++++++++++---- include/linux/checkpoint.h | 1 + include/linux/checkpoint_hdr.h | 6 +++ include/linux/tty.h | 5 +++ 5 files changed, 115 insertions(+), 9 deletions(-)
checkpoint/signal.c +77 -2
@@ -316,11 +316,12 @@ static int checkpoint_signal(struct ckpt_ctx *ctx, struct task_struct *t)struct ckpt_hdr_signal *h;struct signal_struct *signal;struct sigpending shared_pending; +struct tty_struct *tty =NULL ;struct rlimit *rlim;struct timeval tval;cputime_t cputime;unsigned long flags; -int i, ret; +int i, ret =0 ; h =ckpt_hdr_get_type (ctx,sizeof (*h),CKPT_HDR_SIGNAL );if (!h)
@@ -398,9 +399,34 @@ static int checkpoint_signal(struct ckpt_ctx *ctx, struct task_struct *t)cputime_to_timeval (signal->it_prof_incr, &tval); h->it_prof_incr =timeval_to_ns (&tval); +/* tty */ +if (signal->leader) { + h->tty_old_pgrp =ckpt_pid_nr (ctx, signal->tty_old_pgrp); + tty =tty_kref_get (signal->tty); +if (tty) { +/* irq is already disabled */ +spin_lock (&tty->ctrl_lock); + h->tty_pgrp =ckpt_pid_nr (ctx, tty->pgrp); +spin_unlock (&tty->ctrl_lock); +tty_kref_put (tty); + } + } +unlock_task_sighand (t, &flags); - ret =ckpt_write_obj (ctx, &h->h); +/* +* If the session is in an ancestor namespace, skip this tty +* and set tty_objref = 0. It will not be explicitly restored, +* but rather inherited from parent pid-ns at restart time. +*/ +if (tty &&ckpt_pid_nr (ctx, tty->session) >0 ) { + h->tty_objref =checkpoint_obj (ctx, tty,CKPT_OBJ_TTY ); +if (h->tty_objref <0 ) + ret = h->tty_objref; + } + +if (!ret) + ret =ckpt_write_obj (ctx, &h->h);if (!ret) ret =checkpoint_sigpending (ctx, &shared_pending);
@@ -471,8 +497,10 @@ static int restore_signal(struct ckpt_ctx *ctx)struct ckpt_hdr_signal *h;struct sigpending new_pending;struct sigpending *pending; +struct tty_struct *tty =NULL ;struct itimerval itimer;struct rlimit rlim; +struct pid *pgrp =NULL ;int i, ret; h =ckpt_read_obj_type (ctx,sizeof (*h),CKPT_HDR_SIGNAL );
@@ -492,6 +520,40 @@ static int restore_signal(struct ckpt_ctx *ctx)if (ret <0 ) goto out; +/* tty - session */ +if (h->tty_objref) { + tty =ckpt_obj_fetch (ctx, h->tty_objref,CKPT_OBJ_TTY ); +if (IS_ERR (tty)) { + ret =PTR_ERR (tty); + goto out; + } +/* this will fail unless we're the session leader */ + ret =tiocsctty (tty,0 ); +if (ret <0 ) + goto out; +/* now restore the foreground group (job control) */ +if (h->tty_pgrp) { +/* +* If tty_pgrp == CKPT_PID_NULL, below will +* fail, so no need for explicit test +*/ + ret =do_tiocspgrp (tty,tty_pair_get_tty (tty), + h->tty_pgrp); +if (ret <0 ) + goto out; + } + }else { +/* +* If tty_objref isn't set, we _keep_ whatever tty we +* already have as a ctty. Why does this make sense ? +* - If our session is "within" the restart context, +* then that session has no controlling terminal. +* - If out session is "outside" the restart context, +* then we're like to keep whatever we inherit from +* the parent pid-ns. +*/ + } +/* * Reset real/virt/prof itimer (in case they were set), to * prevent unwanted signals after flushing current signals
@@ -503,7 +565,20 @@ static int restore_signal(struct ckpt_ctx *ctx)do_setitimer (ITIMER_VIRTUAL , &itimer,NULL );do_setitimer (ITIMER_PROF , &itimer,NULL ); +/* tty - tty_old_pgrp */ +if (current->signal->leader && h->tty_old_pgrp !=CKPT_PID_NULL ) { +rcu_read_lock (); + pgrp =get_pid (_ckpt_find_pgrp (ctx, h->tty_old_pgrp)); +rcu_read_unlock (); +if (!pgrp) + goto out; + } +spin_lock_irq (¤t->sighand->siglock); +/* tty - tty_old_pgrp */ +put_pid (current->signal->tty_old_pgrp); + current->signal->tty_old_pgrp = pgrp; +/* pending signals */ pending = ¤t->signal->shared_pending;flush_sigqueue (pending); pending->signal = new_pending.signal;
drivers/char/tty_io.c +26 -7
@@ -2130,7 +2130,7 @@ static int fionbio(struct file *file, int __user *p)* Takes ->siglock() when updating signal->tty */ -static int tiocsctty (struct tty_struct *tty,int arg) +int tiocsctty (struct tty_struct *tty,int arg) {int ret =0 ;if (current->signal->leader && (task_session (current) == tty->session))
@@ -2219,10 +2219,10 @@ static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t }/** -* tiocspgrp - attempt to set process group +* do_tiocspgrp - attempt to set process group * @tty: tty passed by user * @real_tty: tty side device matching tty passed by user -* @p: pid pointer +* @pid: pgrp_nr * * Set the process group of the tty to the session passed. Only * permitted where the tty session is our session.
@@ -2230,10 +2230,10 @@ static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t* Locking: RCU, ctrl lock */ -static int tiocspgrp (struct tty_struct *tty,struct tty_struct *real_tty,pid_t __user *p) +int do_tiocspgrp (struct tty_struct *tty, +struct tty_struct *real_tty,pid_t pgrp_nr) {struct pid *pgrp; -pid_t pgrp_nr;int retval =tty_check_change (real_tty);unsigned long flags;
@@ -2245,8 +2245,6 @@ static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t (current->signal->tty != real_tty) || (real_tty->session != task_session(current))) return -ENOTTY; -if (get_user (pgrp_nr, p)) -return -EFAULT ;if (pgrp_nr <0 )return -EINVAL ;rcu_read_lock ();
@@ -2268,6 +2266,27 @@ out_unlock: }/** +* tiocspgrp - attempt to set process group +* @tty: tty passed by user +* @real_tty: tty side device matching tty passed by user +* @p: pid pointer +* +* Set the process group of the tty to the session passed. Only +* permitted where the tty session is our session. +* +* Locking: RCU, ctrl lock +*/ + +static int tiocspgrp (struct tty_struct *tty,struct tty_struct *real_tty,pid_t __user *p) +{ +pid_t pgrp_nr; + +if (get_user (pgrp_nr, p)) +return -EFAULT ; +return do_tiocspgrp (tty, real_tty, pgrp_nr); +} + +/** * tiocgsid - get session id * @tty: tty passed by user * @real_tty: tty side of the tty pased by the user if a pty else the tty
include/linux/checkpoint.h +1 -0
@@ -84,6 +84,7 @@ extern char *ckpt_fill_fname(struct path *path, struct path *root,/* pids */ extern pid_t ckpt_pid_nr (struct ckpt_ctx *ctx,struct pid *pid); +extern struct pid *_ckpt_find_pgrp (struct ckpt_ctx *ctx,pid_t pgid);/* socket functions */ extern int ckpt_sock_getnames(struct ckpt_ctx *ctx,
include/linux/checkpoint_hdr.h +6 -0
@@ -578,13 +578,19 @@ struct ckpt_rlimit {struct ckpt_hdr_signal {struct ckpt_hdr h; +/* rlimit */ struct ckpt_rlimit rlim[CKPT_RLIM_NLIMITS ]; +/* itimer */ __u64 it_real_value;__u64 it_real_incr;__u64 it_virt_value;__u64 it_virt_incr;__u64 it_prof_value;__u64 it_prof_incr; +/* tty */ +__s32 tty_objref; +__s32 tty_pgrp; +__s32 tty_old_pgrp; } __attribute__((aligned (8 )));struct ckpt_hdr_signal_task {
include/linux/tty.h +5 -0
@@ -471,6 +471,11 @@ extern void tty_ldisc_enable(struct tty_struct *tty);/* This one is for ptmx_close() */ extern int tty_release (struct inode *inode,struct file *filp); +/* These are for checkpoint/restart */ +extern int tiocsctty (struct tty_struct *tty,int arg); +extern int do_tiocspgrp (struct tty_struct *tty, +struct tty_struct *real_tty,pid_t pgrp_nr); +#ifdef CONFIG_CHECKPOINT struct ckpt_ctx ;struct ckpt_hdr_file ;
Signature · 7 lines
1.6.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v18 75/80 powerpc: reserve checkpoint arch identifiers
In reply to Oren LaadanFrom: Nathan Lynch <[email protected]>
--- include/linux/checkpoint_hdr.h | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
include/linux/checkpoint_hdr.h +2 -0
@@ -117,6 +117,8 @@ enum {/* do not change order (will break ABI) */ CKPT_ARCH_X86_32 =1 ,CKPT_ARCH_S390X , +CKPT_ARCH_PPC32 , + CKPT_ARCH_PPC64, };/* shared objrects (objref) */
Signature · 7 lines
1.6.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v18 76/80 powerpc: provide APIs for validating and updating DABR
In reply to Oren LaadanFrom: Nathan Lynch <[email protected]>
A checkpointed task image may specify a value for the DABR (Data Access Breakpoint Register). The restart code needs to validate this value before making any changes to the current task.
ptrace_set_debugreg encapsulates the bounds checking and platform dependencies of programming the DABR. Split this into "validate" (debugreg_valid) and "update" (debugreg_update) functions, and make them available for use outside of the ptrace code.
Also ptrace_set_debugreg has extern linkage, but no users outside of ptrace.c. Make it static.
--- arch/powerpc/include/asm/ptrace.h | 7 +++ arch/powerpc/kernel/ptrace.c | 88 +++++++++++++++++++++++++------------ 2 files changed, 66 insertions(+), 29 deletions(-)
arch/powerpc/include/asm/ptrace.h +7 -0
@@ -81,6 +81,8 @@ struct pt_regs {#ifndef __ASSEMBLY__ +#include <linux/types.h> +#define instruction_pointer (regs) ((regs)->nip)#define user_stack_pointer (regs) ((regs)->gpr[1])#define regs_return_value (regs) ((regs)->gpr[3])
@@ -140,6 +142,11 @@ extern void user_enable_single_step(struct task_struct *);extern void user_enable_block_step (struct task_struct *);extern void user_disable_single_step (struct task_struct *); +/* for reprogramming DABR/DAC during restart of a checkpointed task */ +extern bool debugreg_valid (unsigned long val,unsigned int index); +extern void debugreg_update (struct task_struct *task,unsigned long val, +unsigned int index); +#endif /* __ASSEMBLY__ */ #endif /* __KERNEL__ */
arch/powerpc/kernel/ptrace.c +59 -29
128 lines not on this page · raw message
Signature · 7 lines
1.6.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v18 77/80 powerpc: checkpoint/restart implementation
In reply to Oren LaadanFrom: Nathan Lynch <[email protected]>
Support for checkpointing and restarting GPRs, FPU state, DABR, and Altivec state.
The portion of the checkpoint image manipulated by this code begins with a bitmask of features indicating the various contexts saved. Fields in image that can vary depending on kernel configuration (e.g. FP regs due to VSX) have their sizes explicitly recorded, except for GPRS, so migrating between ppc32 and ppc64 won't work yet.
The restart code ensures that the task is not modified until the checkpoint image is validated against the current kernel configuration and hardware features (e.g. can't restart a task using Altivec on non-Altivec systems).
What works:
* self and external checkpoint of simple (single thread, one open file) 32- and 64-bit processes on a ppc64 kernel
What doesn't work:
* restarting a 32-bit task from a 64-bit task and vice versa
Untested:
* ppc32 (but it builds)
[Oren Laadan <[email protected]>] Add arch-specific tty support
--- arch/powerpc/include/asm/Kbuild | 1 + arch/powerpc/include/asm/checkpoint_hdr.h | 37 ++ arch/powerpc/mm/Makefile | 1 + arch/powerpc/mm/checkpoint.c | 531 +++++++++++++++++++++++++++++ 4 files changed, 570 insertions(+), 0 deletions(-) create mode 100644 arch/powerpc/include/asm/checkpoint_hdr.h create mode 100644 arch/powerpc/mm/checkpoint.c
arch/powerpc/include/asm/Kbuild +1 -0
@@ -12,6 +12,7 @@ header-y += shmbuf.h header-y += socket.h header-y += termbits.h header-y += fcntl.h +header-y += checkpoint_hdr.h header-y += poll.h header-y += sockios.h header-y += ucontext.h
arch/powerpc/include/asm/checkpoint_hdr.h new file +37 -0
@@ -0,0 +1,37 @@ +#ifndef __ASM_POWERPC_CKPT_HDR_H +#define __ASM_POWERPC_CKPT_HDR_H + +#include <linux/types.h> + +/* arch dependent constants */ +#define CKPT_ARCH_NSIG 64 +#define CKPT_TTY_NCC 10 + +#ifdef __KERNEL__ + +#include <asm/signal.h> +#if CKPT_ARCH_NSIG != _NSIG +#error CKPT_ARCH_NSIG size is wrong per asm/signal.h and asm/checkpoint_hdr.h +#endif + +#include <linux/tty.h> +#if CKPT_TTY_NCC !=NCC +#error CKPT_TTY_NCC size is wrong per asm-generic/termios.h +#endif + +#endif /* __KERNEL__ */ + +#ifdef __KERNEL__ +#ifdef CONFIG_PPC64 +#define CKPT_ARCH_ID CKPT_ARCH_PPC64 +#else +#define CKPT_ARCH_ID CKPT_ARCH_PPC32 +#endif +#endif + +struct ckpt_hdr_header_arch { +struct ckpt_hdr h; +__u32 what; +} __attribute__((aligned (8 ))); + +#endif /* __ASM_POWERPC_CKPT_HDR_H */
arch/powerpc/mm/Makefile +1 -0
@@ -31,3 +31,4 @@ obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o obj-$(CONFIG_PPC_SUBPAGE_PROT) += subpage-prot.o obj-$(CONFIG_NOT_COHERENT_CACHE) += dma-noncoherent.o obj-$(CONFIG_HIGHMEM) += highmem.o +obj-$(CONFIG_CHECKPOINT) += checkpoint.o
arch/powerpc/mm/checkpoint.c new file +531 -0
531 lines not on this page · raw message
Signature · 6 lines
1.6.0.4 -- To unsubscribe from this list: send the line "unsubscribe linux-api" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v18 78/80 powerpc: wire up checkpoint and restart syscalls
In reply to Oren LaadanFrom: Nathan Lynch <[email protected]>
--- arch/powerpc/include/asm/systbl.h | 2 ++ arch/powerpc/include/asm/unistd.h | 4 +++- 2 files changed, 5 insertions(+), 1 deletions(-)
arch/powerpc/include/asm/systbl.h +2 -0
@@ -326,3 +326,5 @@ SYSCALL_SPU(perf_counter_open) COMPAT_SYS_SPU(preadv) COMPAT_SYS_SPU(pwritev) COMPAT_SYS(rt_tgsigqueueinfo) +SYSCALL(checkpoint) +SYSCALL(restart)
arch/powerpc/include/asm/unistd.h +3 -1
@@ -345,10 +345,12 @@#define __NR_preadv 320#define __NR_pwritev 321#define __NR_rt_tgsigqueueinfo 322 +#define __NR_checkpoint 323 +#define __NR_restart 324#ifdef __KERNEL__ -#define __NR_syscalls 323 +#define __NR_syscalls 325#define __NR__exit __NR_exit#define NR_syscalls __NR_syscalls
Signature · 7 lines
1.6.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v18 79/80 powerpc: enable checkpoint support in Kconfig
In reply to Oren LaadanFrom: Nathan Lynch <[email protected]>
--- arch/powerpc/Kconfig | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
arch/powerpc/Kconfig +3 -0
@@ -26,6 +26,9 @@ config MMU bool default y +config CHECKPOINT_SUPPORT + def_bool y + config GENERIC_CMOS_UPDATE def_bool y
Signature · 7 lines
1.6.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v18 80/80 powerpc: clone_with_pids implementation
In reply to Oren LaadanFrom: Nathan Lynch <[email protected]>
Mostly copy-paste from existing clone code.
(may want to hold off applying this until the ongoing clone_with_pids discussion is resolved.)
--- arch/powerpc/include/asm/syscalls.h | 4 ++++ arch/powerpc/include/asm/systbl.h | 1 + arch/powerpc/include/asm/unistd.h | 3 ++- arch/powerpc/kernel/entry_32.S | 8 ++++++++ arch/powerpc/kernel/entry_64.S | 5 +++++ arch/powerpc/kernel/process.c | 20 +++++++++++++++++++- 6 files changed, 39 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/syscalls.h +4 -0
@@ -24,6 +24,10 @@ asmlinkage int sys_execve(unsigned long a0, unsigned long a1, asmlinkage int sys_clone(unsigned long clone_flags, unsigned long usp,int __user *parent_tidp,void __user *child_threadptr,int __user *child_tidp,int p6,struct pt_regs *regs); +asmlinkage int sys_clone_with_pids(unsigned long clone_flags, +unsigned long usp,int __user *parent_tidp, +void __user *child_threadptr,int __user *child_tidp, +void __user *upid_setp,struct pt_regs *regs); asmlinkage int sys_fork(unsigned long p1, unsigned long p2,unsigned long p3,unsigned long p4,unsigned long p5,unsigned long p6,struct pt_regs *regs);
arch/powerpc/include/asm/systbl.h +1 -0
@@ -328,3 +328,4 @@ COMPAT_SYS_SPU(pwritev) COMPAT_SYS(rt_tgsigqueueinfo) SYSCALL(checkpoint) SYSCALL(restart) +PPC_SYS(clone_with_pids)
arch/powerpc/include/asm/unistd.h +2 -1
@@ -347,10 +347,11 @@#define __NR_rt_tgsigqueueinfo 322#define __NR_checkpoint 323#define __NR_restart 324 +#define __NR_clone_with_pids 325#ifdef __KERNEL__ -#define __NR_syscalls 325 +#define __NR_syscalls 326#define __NR__exit __NR_exit#define NR_syscalls __NR_syscalls
arch/powerpc/kernel/entry_32.S +8 -0
@@ -586,6 +586,14 @@ ppc_clone: stw r0,_TRAP(r1) /* register set saved */ b sys_clone + .globl ppc_clone_with_pids +ppc_clone_with_pids: + SAVE_NVGPRS(r1) + lwz r0,_TRAP(r1) + rlwinm r0,r0,0,0,30 /* clear LSB to indicate full */ + stw r0,_TRAP(r1) /* register set saved */ + b sys_clone_with_pids + .globl ppc_swapcontext ppc_swapcontext: SAVE_NVGPRS(r1)
arch/powerpc/kernel/entry_64.S +5 -0
@@ -320,6 +320,11 @@ _GLOBAL(ppc_clone) bl .sys_clone b syscall_exit +_GLOBAL(ppc_clone_with_pids) + bl .save_nvgprs + bl .sys_clone_with_pids + b syscall_exit + _GLOBAL(ppc32_swapcontext) bl .save_nvgprs bl .compat_sys_swapcontext
arch/powerpc/kernel/process.c +19 -1
@@ -895,7 +895,25 @@ int sys_clone(unsigned long clone_flags, unsigned long usp, child_tidp =TRUNC_PTR (child_tidp); }#endif -return do_fork (clone_flags, usp, regs,0 , parent_tidp, child_tidp); +return do_fork (clone_flags, usp, regs,0 , parent_tidp, child_tidp); +} + +int sys_clone_with_pids (unsigned long clone_flags,unsigned long usp, +int __user *parent_tidp,void __user *child_threadptr, +int __user *child_tidp,void __user *upid_setp, +struct pt_regs *regs) +{ +CHECK_FULL_REGS (regs); +if (usp ==0 ) + usp = regs->gpr[1 ]; +#ifdef CONFIG_PPC64 +if (test_thread_flag (TIF_32BIT )) { + parent_tidp =TRUNC_PTR (parent_tidp); + child_tidp =TRUNC_PTR (child_tidp); + } +#endif +return do_fork_with_pids (clone_flags, usp, regs,0 , + parent_tidp, child_tidp, upid_setp); } int sys_fork(unsigned long p1, unsigned long p2, unsigned long p3,
Signature · 7 lines
1.6.0.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi Oren,
I am getting following build error while compiling linux-cr kernel.
git://git.ncl.cs.columbia.edu/pub/git/linux-cr.git
...
76569 net/unix/af_unix.c:528: error: ‘unix_collect’ undeclared here (not in a function) 76570 LD [M] drivers/net/enic/enic.o
76571 make[2]: *** [net/unix/af_unix.o] Error 1
76572 make[1]: *** [net/unix] Error 2
76573 make: *** [net] Error 2
76574 make: *** Waiting for unfinished jobs....
...
Let me know if you need config file.
-Rishi
Quoted 371 lines · Oren Laadan
Hi Andrew,
This is our recent round of checkpoint/restart patches. It can
checkpoint and restart interactive sessions of 'screen' across kernel reboot. Please consider applying to -mm.Patches 1-17 are clean-ups and preparations for c/r:
* 1,2,3,4 and 9,10: cleanups, also useful for c/r.
* 5,6: fix freezer control group
* 7,8: extend freezer control group for c/r.
* 11-17:clone_with_pidPatch 18 reserves the system calls slots - please apply so we don't need to keep changing them.
Patches 19-80 contain the actual c/r code; we've exhausted the reviewers for most of them.
Patch 32 implements a deferqueue - mechanism for a process to defer work for some later time (unlike workqueue, designed for the work to execute in the context of same/original process).
Thanks,
Oren.
----
Application checkpoint/restart (c/r) is the ability to save the state of a running application so that it can later resume its execution from the time at which it was checkpointed, on the same or a different machine.
This version brings support many new features, including support for unix domain sockets, fifos, pseudo-terminals, and signals (see the detailed changelog below).
With these in place, it can now checkpoint and restart not only batch jobs, but also interactive programs using 'screen'. For example, users can checkpoint a 'screen' session with multiple shells, upgrade their kernel, reboot, and restart their interactive 'screen' session from before !
This patchset was compiled and tested against v2.6.31. For more information, check out
Documentation/checkpoint/*.txtQ: How useful is this code as it stands in real-world usage?
A: The application can be single- or multi-processes and threads. It
handles open files (regular files/directories on most file systems, pipes, fifos,af_unixsockets,/dev/{null,zero,random,urandom}and pseudo-terminals. It supports shared memory. sysv IPC (except undo of sempahores). It's suitable for many types of batch jobs as well as some interactive jobs. (Note: it is assumed that the fs view is available at restart).Q: What can it checkpoint and restart ?
A: A (single threaded) process can checkpoint itself, aka "self"
checkpoint, if it calls the new system calls. Otherise, for an "external" checkpoint, the caller must first freeze the target processes. One can either checkpoint an entire container (and we make best effort to ensure that the result is self-contained), or merely a subtree of a process hierarchy.Q: What about namespaces ?
A: Currrently, UTS and IPC namespaces are restored. They demonstrate
how namespaces are handled. More to come.Q: What additional work needs to be done to it?
A: Fill in the gory details following the examples so far. Current WIP
includes inet sockets, event-poll, and early work on inotify, mount namespace and mount-points, pseudo file systems, andx86_64support.Q: How can I try it ?
A: Use it for simple batch jobs (pipes, too), or an interactive
'screen' session, in a whole container or just a subtree of tasks:create the freezer cgroup:
$ mount -t cgroup -ofreezer freezer /cgroup $ mkdir /cgroup/0run the test, freeze it:
$ test/multitask & [1] 2754 $ for i in `pidof multitask`; do echo $i > /cgroup/0/tasks; done $ echo FROZEN > /cgruop/0/freezer.statecheckpoint:
$ ./ckpt 2754 > ckpt.outrestart:
$ ./mktree < ckpt.outvoila :)
To do all this, you'll need:
The git tree tracking v18, branch 'ckpt-v18' (and past versions):
git://git.ncl.cs.columbia.edu/pub/git/linux-cr.gitThe userspace tools are available through the matching branch [v18]:
git://git.ncl.cs.columbia.edu/pub/git/user-cr.gitChangelog:
[2009-Sep-22] v18
(new features)
- [Nathan Lynch] Re-introduce powerpc support
- Save/restore pseudo-terminals
- Save/restore (pty) controlling terminals
- Save/restore restore PGIDs
- [Dan Smith] Save/restore unix domain sockets
- Save/restore FIFOs
- Save/restore pending signals
- Save/restore rlimits
- Save/restore itimers
- [Matt Helsley] Handle many non-pseudo file-systems(other changes)
- Rename headerless struct ckpt_hdr_* to struct ckpt_*
- [Nathan Lynch] discard const from struct cred * where appropriate
- [Serge Hallyn][s390] Set return value for self-checkpoint
- Handle kmalloc failure inrestore_sem_array()
- [IPC] Collect files used by shm objects
- [IPC] Use file (not inode) as shared object on checkpoint of shm
- More ckpt_write_err()s to give information on checkpoint failure
- Adjust format of pipe buffer to include the mandatory pre-header
- [LEAKS] Mark the backing file as visited at chekcpoint
- Tighten checks on supported vma to checkpoint or restart
- [Serge Hallyn] Exportfilemap_checkpoint()(used for ext4)
- Introduceckpt_collect_file()that also usesfile->collectmethod
- Useckpt_collect_file()instead ofckpt_obj_collect()for files
- Fix leak-detection issue incollect_mm()(test for first-time obj)
- Invokeset_close_on_exec()unconditionally on restart
- [Dan Smith] Exportfill_fname()asckpt_fill_fname()
- Interface to pass simple pointers as data with deferqueue
- [Dan Smith] Fixckpt_obj_lookup_add()leak detection logic
- Replace EAGAIN with EBUSY where necessary
- IntroduceCKPT_OBJ_VISITEDin leak detection
-ckpt_obj_collect()returns objref for new objects, 0 otherwise
- Renameckpt_obj_checkpointed()tockpt_obj_visited()
- Introduceckpt_obj_visit()to mark objects as visited
- Set the CHECKPOINTED flag on objects before calling checkpoint
- Introduceckpt_obj_reserve()
- Changeref_drop()to accept a @lastref argument (for cleanup)
- Disallow multiple objects with same objref in restart
- Allow_ckpt_read_obj_type()to read header only (w/o payload)
- Fix leak ofckpt_ctxwhen restoring zombie tasks
- Fix race ofprepare_descendant()with an ongoingfork()
- Track and report the first error if restart fails
- Tighten logic to protect against bogus pids in input
- [Matt Helsley] Improve debug output fromckpt_notify_error()
- [Nathan Lynch] fix compilation errors withCONFIG_COMPAT=y
- Detect error-headers in input data on restart, and abort.
- Standard format for checkpoint error strings (and documentation)
- [Dan Smith] Add an errno validation function
- Addckpt_read_payload(): read a variable-length object (no header)
- Addckpt_read_string(): same for strings (ensures null-terminated)
- Addckpt_read_consume(): consumes next object without processing
- [John Dykstra] Fix no-dot-config-targets pattern in linux/Makefile[2009-Jul-21] v17
- Introduce syscallclone_with_pids()to restore original pids
- Support threads and zombies
- Save/restoretask->files
- Save/restoretask->sighand
- Save/restore futex
- Save/restore credentials
- IntroducePF_RESTARTINGto skip notifications on task exit
- restart(2) allow caller to ask to freeze tasks after restart
- restart(2) isn't idempotent: return-EINTRif interrupted
- Improve debugging output handling
- Make multi-process restart logic more robust and complete
- Correctly select return value for restarting tasks on success
- Tighten ptrace test for checkpoint toPTRACE_MODE_ATTACH
- Use CHECKPOINTING state for frozen checkpointed tasks
- Fix compilation withoutCONFIG_CHECKPOINT
- Fix compilation withCONFIG_COMPAT
- Fix headers includes and exports
- Leak detection performed in two steps
- Detect "inverse" leaks of objects (dis)appearing unexpectedly
- Memory: save/restore mm->{flags,def_flags,saved_auxv}
- Memory: only collect sub-objects of mm once (leak detection)
- Files: validatef_modeafter restore
- Namespaces: leak detection for nsproxy sub-components
- Namespaces: proper restart from namespace(s) without namespace(s)
- Save global constants in header instead of per-object
- IPC: replacesys_unshare()withcreate_ipc_ns()
- IPC: restore objects in suitable namespace
- IPC: correct behavior under !CONFIG_IPC_NS
- UTS: save/restore all fields
- UTS: replacesys_unshare()withcreate_uts_ns()
-X86_32: sanitize cpu, debug, and segment registers on restart
-cgroup_freezer: add CHECKPOINTING state to safeguard checkpoint
-cgroup_freezer: add interface to freeze a cgroup (given a task)[2009-May-27] v16
- Privilege checks for IPC checkpoint
- Fix error string generation during checkpoint
- Use kzalloc for header allocation
- Restart blocks are arch-independent
- Redo pipe c/r using splice
- Fixes to s390 arch
- Remove powerpc arch (temporary)
- Explicitly restore ->nsproxy
- All objects in image are precedeed by 'structckpt_hdr'
- Fix leaks detection (and leaks)
- Reorder of patchset
- Misc bugs and compilation fixes[2009-Apr-12] v15
- Minor fixes[2009-Apr-28] v14
- Tested against kernel v2.6.30-rc3 onx86_32.
- Refactor files chekpoint to usef_ops(file operations)
- Refactor mm/vma to usevma_ops
- Explicitly handle VDSO vma (and require compat mode)
- Added code to c/r restat-blocks (restart timeout related syscalls)
- Added code to c/r namespaces: uts, ipc (with Dan Smith)
- Added code to c/r sysvipc (shm, msg, sem)
- Support forVM_CLONEshared memory
- Added resource leak detection for whole-container checkpoint
- Added sysctl gauge to allow unprivileged restart/checkpoint
- Improve and simplify the code and logic of shared objects
- Rework image format: shared objects appear prior to their use
- Merge checkpoint and restart functionality into same files
- Massive renaming of functions: prefix "ckpt_" for generics, "checkpoint_" for checkpoint, and "restore_" for restart.
- Report checkpoint errors as a valid (string record) in the output
- Merged PPC architecture (by Nathan Lunch),
- Requires updates to userspace tools too.
- Misc nits and bug fixes[2009-Mar-31] v14-rc2
- Change along Dave's suggestion to usef_ops->checkpoint()for files
- Merge patch simplifyingKconfig, withCONFIG_CHECKPOINT_SUPPORT
- Merge support for PPC arch (Nathan Lynch)
- Misc cleanups and fixes in response to comments[2009-Mar-20] v14-rc1:
- The 'h.parent' field of 'structcr_hdr' isn't used - discard
- Check whether calls tocr_hbuf_get()succeed or fail.
- Fixed of pipe c/r code
- Prevent deadlock by refusing c/r when a pipe inode ==ctx->fileinode
- Refuse non-self checkpoint if a task isn't frozen
- Use unsigned fields in checkpoint headers unless otherwise required
- Rename functions in files c/r to better reflect their role
- Add support for anonymous shared memory
- Merge support for s390 arch (Dan Smith, Serge Hallyn)[2008-Dec-03] v13:
- Cleanups of 'structcr_ctx' - remove unused fields
- Misc fixes for comments[2008-Dec-17] v12:
- Fix re-alloc/reset of pgarr chain to correctly reuse buffers (empty pgarr are saves in a separate pool chain)
- Add a couple of missed calls tocr_hbuf_put()
- cr_kwrite/cr_kread() again usevfs_read(),vfs_write()(safer)
- Split cr_write/cr_read() to two parts: _cr_write/read() helper
- Befriend with sparse: explicit conversion to 'void__user*'
- Redrefine 'pr_fmt' ind replacecr_debug()withpr_debug()[2008-Dec-05] v11:
- Use contents of 'init->fs->root' instead of pointing to it
- Ignore symlinks (there is no such thing as an open symlink)
-cr_scan_fds()retries from scratch if it hits size limits
- Add missing test forVM_MAYSHAREwhen dumping memory
- Improve documentation about: behavior when tasks aren't fronen, life span of the object hash, references to objects in the hash[2008-Nov-26] v10:
- Grab vfs root of container init, rather than current process
- Acquiredcache_lockaround call to__d_path()incr_fill_name()
- Force end-of-string incr_read_string()(fix possible DoS)
- Introducecr_write_buffer(),cr_read_buffer()andcr_read_buf_type()[2008-Nov-10] v9:
- Support multiple processes c/r
- Extend checkpoint header with archtiecture dependent header
- Misc bug fixes (see individual changelogs)
- Rebase to v2.6.28-rc3.[2008-Oct-29] v8:
- Support "external" checkpoint
- Include Dave Hansen's 'deny-checkpoint' patch
- Split docs inDocumentation/checkpoint/..., and improve contents[2008-Oct-17] v7:
- Fix save/restore state of FPU
- Fix argument given tokunmap_atomic()in memory dump/restore[2008-Oct-07] v6:
- Balance all calls tocr_hbuf_get()with matchingcr_hbuf_put()(even though it's not really needed)
- Add assumptions and what's-missing to documentation
- Misc fixes and cleanups[2008-Sep-11] v5:
- Config is now 'def_booln' by default
- Improve memory dump/restore code (following Dave Hansen's comments)
- Change dump format (and code) to allow chunks of <vaddrs, pages> instead of one long list of each
- Fix use offollow_page()to avoid faulting in non-present pages
- Memory restore now maps user pages explicitly to copy data into them, instead of reading directly to user space; got rid ofmprotect_fixup()
- Removepreempt_disable()when restoring debug registers
- Rename headers files s/ckpt/checkpoint/
- Fix misc bugs in files dump/restore
- Fixes and cleanups on some error paths
- Fix misc coding style[2008-Sep-09] v4:
- Various fixes and clean-ups
- Fix calculation of hash table size
- Fix header structure alignment
- Use standlist_... forcr_pgarr[2008-Aug-29] v3:
- Various fixes and clean-ups
- Use standardhlist_... for hash table
- Better use of standard kmalloc/kfree[2008-Aug-20] v2:
- Added Dump and restore of open files (regular and directories)
- Added basic handling of shared objects, and improve handling of 'parent tag' concept
- Added documentation
- Improved ABI, 64bit padding for image data
- Improved locking when saving/restoring memory
- Added UTS information to header (release, version, machine)
- Cleanup extraction of filename from a file pointer
- Refactor to allow easier reviewing
- Remove requirement forCAPS_SYS_ADMINuntil we come up with a security policy (this means that file restore may fail)
- Other cleanup and response to comments for v1[2008-Jul-29] v1:
- Initial version: support a single task with address space of only private anonymous or file-mapped VMAs; syscalls ignore pid/crid argument and act on current process.--
At the containers mini-conference before OLS, the consensus among all the stakeholders was that doing checkpoint/restart in the kernel as much as possible was the best approach. With this approach, the kernel will export a relatively opaque 'blob' of data to userspace which can then be handed to the new kernel at restore time.This is different than what had been proposed before, which was that a userspace application would be responsible for collecting all of this data. We were also planning on adding lots of new, little kernel interfaces for all of the things that needed checkpointing. This unites those into a single, grand interface.
The 'blob' will contain copies of select portions of kernel structures such as vmas and
mm_structs. It will also contain copies of the actual memory that the process uses. Any changes in this blob's format between kernel revisions can be handled by an in-userspace conversion program.This is a similar approach to virtually all of the commercial checkpoint/restart products out there, as well as the research project Zap.
These patches basically serialize internel kernel state and write it out to a file descriptor. The checkpoint and restore are done with two new system calls:
sys_checkpointandsys_restart.
Quoted 10 lines
In this incarnation, they can only work checkpoint and restore a single task. The task's address space may consist of only private, simple vma's - anonymous or file-mapped. The open files may consist of only simple files and directories.
--
_______________________________________________
Containers mailing list [email protected]
https://lists.linux-foundation.org/mailman/listinfo/containers
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
R> I am getting following build error while compiling linux-cr kernel.
With CONFIG_CHECKPOINT=n, right?
R> 76569 net/unix/af_unix.c:528: error: ‘unix_collect’ undeclared here (not R> in a function)
Try the patch below.
Signature · 3 lines
Dan Smith IBM Linux Technology Center email: [email protected]
include/net/af_unix.h +1 -0
@@ -80,6 +80,7 @@ extern int unix_collect(struct ckpt_ctx *ctx, struct socket *sock);#else #define unix_checkpoint NULL#define unix_restore NULL +#define unix_collect NULL#endif /* CONFIG_CHECKPOINT */ #endif
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 8 lines · Dan Smith
R> I am getting following build error while compiling linux-cr kernel.
With
CONFIG_CHECKPOINT=n, right?R> 76569
net/unix/af_unix.c:528: error: ‘unix_collect’ undeclared here (not R> in a function)Try the patch below.
Yes attached patch solves the prob. Thanks Dan.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
A message that is not in the archive (sent off-list or not yet received): 878wg41f65.fsf-FLMGYpZoEPULwtHQx/[email protected]
Quoted 9 lines · Dan Smith
R> I am getting following build error while compiling linux-cr kernel.
With
CONFIG_CHECKPOINT=n, right?R> 76569
net/unix/af_unix.c:528: error: ‘unix_collect’ undeclared here (not R> in a function)Try the patch below.
Yes attached patch solves the prob. Thanks Dan.
_______________________________________________
Containers mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/containers
R> I am getting following build error while compiling linux-cr kernel.
With CONFIG_CHECKPOINT=n, right?
R> 76569 net/unix/af_unix.c:528: error: ‘unix_collect’ undeclared here (not R> in a function)
Try the patch below.
Signature · 3 lines
Dan Smith IBM Linux Technology Center email: [email protected]
include/net/af_unix.h +1 -0
@@ -80,6 +80,7 @@ extern int unix_collect(struct ckpt_ctx *ctx, struct socket *sock);#else #define unix_checkpoint NULL#define unix_restore NULL +#define unix_collect NULL#endif /* CONFIG_CHECKPOINT */ #endif
_______________________________________________
Containers mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/containers
Andrew Morton
maintainerQuoted 8 lines · On Wed, 23 Sep 2009 19:50:40 -0400 Oren Laadan <[email protected]> wrote:
Q: How useful is this code as it stands in real-world usage?
A: The application can be single- or multi-processes and threads. It
handles open files (regular files/directories on most file systems, pipes, fifos,af_unixsockets,/dev/{null,zero,random,urandom}and pseudo-terminals. It supports shared memory. sysv IPC (except undo of sempahores). It's suitable for many types of batch jobs as well as some interactive jobs. (Note: it is assumed that the fs view is available at restart).
That's encouraging.
Quoted 7 lines
Q: What can it checkpoint and restart ?
A: A (single threaded) process can checkpoint itself, aka "self"
checkpoint, if it calls the new system calls. Otherise, for an "external" checkpoint, the caller must first freeze the target processes. One can either checkpoint an entire container (and we make best effort to ensure that the result is self-contained), or merely a subtree of a process hierarchy.
What is "best effort"? Will the operation appear to have succeeded, only it didn't?
IOW, how reliable and robust is code at detecting that it was unable to successfully generate a restartable image?
Quoted 3 lines
Q: What about namespaces ?
A: Currrently, UTS and IPC namespaces are restored. They demonstrate
how namespaces are handled. More to come.
Will this new code muck up the kernel?
Quoted 4 lines
Q: What additional work needs to be done to it?
A: Fill in the gory details following the examples so far. Current WIP
includes inet sockets, event-poll, and early work on inotify, mount namespace and mount-points, pseudo file systems
Will this new code muck up the kernel, or will it be clean?
Quoted 1 line
and
x86_64support.
eh? You mean the code doesn't work on x86_64 at present?
What is the story on migration? Moving the process(es) to a different machine?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 4 lines
Quoted 4 lines
Q: What additional work needs to be done to it? A: Fill in the gory details following the examples so far. Current WIP includes inet sockets, event-poll, and early work on inotify, mount namespace and mount-points, pseudo file systems
AM> Will this new code muck up the kernel, or will it be clean?
I have (and have previously posted) prototype code to do c/r of open sockets, ignoring some things like updating timers and such. It looks rather similar to the existing UNIX bits, and is even easier in some ways.
One particular use case is only migrating listening sockets and allowing the connected ones to be reset upon restart. That enables a bunch of things like apache, postfix, vncserver, and even sshd. I will pull the listen-only bits out of my current patch, scrape off a little bitrot, and post them in a few days.
Signature · 9 lines
Dan Smith IBM Linux Technology Center email: [email protected] -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 12 lines · Dan Smith
Quoted 4 lines
Quoted 4 lines
Q: What additional work needs to be done to it? A: Fill in the gory details following the examples so far. Current WIP includes inet sockets, event-poll, and early work on inotify, mount namespace and mount-points, pseudo file systems
AM> Will this new code muck up the kernel, or will it be clean?
I have (and have previously posted) prototype code to do c/r of open sockets, ignoring some things like updating timers and such. It looks rather similar to the existing UNIX bits, and is even easier in some ways.
Quoted 5 lines
One particular use case is only migrating listening sockets and allowing the connected ones to be reset upon restart. That enables a bunch of things like apache, postfix, vncserver, and even sshd. I will pull the listen-only bits out of my current patch, scrape off a little bitrot, and post them in a few days.
That looks useful. (Btw., the other four questions Andrew asked look relevant too.)
Ingo
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
A message that is not in the archive (sent off-list or not yet received): 87ljk39lcl.fsf-FLMGYpZoEPULwtHQx/[email protected]
Quoted 12 lines · Dan Smith
Quoted 4 lines
Quoted 4 lines
Q: What additional work needs to be done to it? A: Fill in the gory details following the examples so far. Current WIP includes inet sockets, event-poll, and early work on inotify, mount namespace and mount-points, pseudo file systems
AM> Will this new code muck up the kernel, or will it be clean?
I have (and have previously posted) prototype code to do c/r of open sockets, ignoring some things like updating timers and such. It looks rather similar to the existing UNIX bits, and is even easier in some ways.
Quoted 5 lines
One particular use case is only migrating listening sockets and allowing the connected ones to be reset upon restart. That enables a bunch of things like apache, postfix, vncserver, and even sshd. I will pull the listen-only bits out of my current patch, scrape off a little bitrot, and post them in a few days.
That looks useful. (Btw., the other four questions Andrew asked look relevant too.)
Ingo
A message that is not in the archive (sent off-list or not yet received): 20090924154139.2a7dd5ec.akpm-de/[email protected]
Quoted 4 lines
Quoted 4 lines
Q: What additional work needs to be done to it? A: Fill in the gory details following the examples so far. Current WIP includes inet sockets, event-poll, and early work on inotify, mount namespace and mount-points, pseudo file systems
AM> Will this new code muck up the kernel, or will it be clean?
I have (and have previously posted) prototype code to do c/r of open sockets, ignoring some things like updating timers and such. It looks rather similar to the existing UNIX bits, and is even easier in some ways.
One particular use case is only migrating listening sockets and allowing the connected ones to be reset upon restart. That enables a bunch of things like apache, postfix, vncserver, and even sshd. I will pull the listen-only bits out of my current patch, scrape off a little bitrot, and post them in a few days.
Signature · 3 lines
Dan Smith IBM Linux Technology Center email: danms-r/[email protected]
Quoted 7 lines · Andrew Morton
Quoted 3 lines · On Wed, 23 Sep 2009 19:50:40 -0400 Oren Laadan…
Q: What about namespaces ?
A: Currrently, UTS and IPC namespaces are restored. They demonstrate
how namespaces are handled. More to come.Will this new code muck up the kernel?
Actually user namespaces are handled as well. Pid namespaces will be named and recorded by kernel at checkpoint, and re-created in userspace using clone(CLONE_NEWPID). This shouldn't muck up the kernel at all. The handling of network and mounts namespaces is at this point undecided. Well, mounts namespaces themselves are pretty simple, but not so much for mountpoints. There it's mainly a question of how to predict what a user wants to have automatically recreated. All mounts which differ between the root checkpoint task and its parent? Do we do no mounts for the restarted init task at all, and only recreate mounts in private child namespaces (i.e. if a task did a unshare(CLONE_NEWNS); mount --make-private /var; mount --bind /container2/var/run /var/run)?
I hear a decision was made at plumber's about how to begin handling them, so I'll let someone (Oren? Dave?) give that info.
For network namespaces i think it's clearer that a wrapper program should set up the network for the restarted init task, while the usrspace code should recreate any private network namespaces and veth's which were created by the application. But it still needs discussion.
Quoted 10 lines
Quoted 4 lines
Q: What additional work needs to be done to it?
A: Fill in the gory details following the examples so far. Current WIP
includes inet sockets, event-poll, and early work on inotify, mount namespace and mount-points, pseudo file systemsWill this new code muck up the kernel, or will it be clean?
Quoted 1 line
and
x86_64support.eh? You mean the code doesn't work on
x86_64at present?
There have been patches for it, but I think the main problem is noone involved has hw to test.
Quoted 2 lines
What is the story on migration? Moving the process(es) to a different machine?
Since that's basically checkpoint; recreate container on remote machine; restart on remote machine; that will mainly be done by userspace code exploiting the c/r kernel patches.
The main thing we may want to add is a way to initiate pre-dump of large amounts of VM while the container is still running. I suspect Oren and Dave can say a lot more about that than I can right now.
thanks,
-serge
Hi,
Quoted 22 lines · Andrew Morton
Quoted 8 lines · On Wed, 23 Sep 2009 19:50:40 -0400 Oren Laadan…
Q: How useful is this code as it stands in real-world usage?
A: The application can be single- or multi-processes and threads. It
handles open files (regular files/directories on most file systems, pipes, fifos,af_unixsockets,/dev/{null,zero,random,urandom}and pseudo-terminals. It supports shared memory. sysv IPC (except undo of sempahores). It's suitable for many types of batch jobs as well as some interactive jobs. (Note: it is assumed that the fs view is available at restart).That's encouraging.
Quoted 7 lines
Q: What can it checkpoint and restart ?
A: A (single threaded) process can checkpoint itself, aka "self"
checkpoint, if it calls the new system calls. Otherise, for an "external" checkpoint, the caller must first freeze the target processes. One can either checkpoint an entire container (and we make best effort to ensure that the result is self-contained), or merely a subtree of a process hierarchy.
Quoted 2 lines
What is "best effort"? Will the operation appear to have succeeded, only it didn't?
There are two modes of operation: a "full" (container) checkpoint and a "subtree" checkpoint.
For container-checkpoint, the application runa within its own set of namespaces (pid, uts, ipc ...). We have a leak-detection algorithm in place to ensure that the application is entirely contained and isolated in the container, or else the checkpoint fails. In this case, restart is guaranteed to succeed (assuming external dependencies are properly set - see below).
A "subtree" checkpoint is less restrictive. It allows to checkpoint applications that aren't truly isolated. In this case, restart may fail, or restart may succeed but the application may fail shortly after because some dependency may be missing. However, in practice this works well for many applications transparently, and even more so for c/r-aware application.
In both modes of operation, some external dependencies are assumed to exist. One example is the file system view that has to be the same for the container (or subtree) as during checkpoint. Another is the network setup. These will be reconstructed (at least in part) by userspace prior to the actual restart.
(Some of these dependencies can be relaxed for many use-cases, e.g. when user/application doesn't care about preserving original network connection after restart).
Quoted 2 lines
IOW, how reliable and robust is code at detecting that it was unable to successfully generate a restartable image?
To the best of my knowledge (and unless someone pokes a hole in the algorithm), container-checkpoint is robust and reliable.
Two reasons for saying "best effort": first, because external dependencies need to be suitably arranged. If external dependencies are not arranged - e.g. provide a snapshot of the filesystem from the time of the checkpoint - restart, or execution thereafter, may fail.
Second, because even when the application is isolated within a container, the user from outside may still be able to affect it. I can think of one (and only one) pathological example: an outside process signals all tasks in a container during a checkpoint, but the signal is recorded for only some tasks. I'd argue that this is improper behavior that we need not support, rather than address it in the kernel.
Quoted 6 lines
Quoted 4 lines
Q: What about namespaces ?
A: Currrently, UTS and IPC namespaces are restored. They demonstrate
how namespaces are handled. More to come.Will this new code muck up the kernel?
I forgot to mention user-ns is already included. We have a good plan for mount-ns and mount-points, and intend to handle net-ns in userspace (by that, I mean the net-ns setup, not the state of connections etc).
I don't expect this additional code to be less solid than the current one.
Quoted 7 lines
Quoted 5 lines
Q: What additional work needs to be done to it?
A: Fill in the gory details following the examples so far. Current WIP
includes inet sockets, event-poll, and early work on inotify, mount namespace and mount-points, pseudo file systemsWill this new code muck up the kernel, or will it be clean?
Should not.
I guess "gory details" was a bad choice of words, and I really meant to say "less interesting". IOW, I think we have constructed a solid and framework. From the kernel side, I think we're left with completeness - add support for remaining missing features (e.g. inotify), and goodies - live migration and other optimizations.
Quoted 9 lines
Quoted 2 lines
and
x86_64support.eh? You mean the code doesn't work on
x86_64at present?What is the story on migration? Moving the process(es) to a different machine?
It depends on the use-case in mind:
Moving processes between machines without preserving external network connections (or IP), already works. This can be useful for servers (e.g. apache, or vnc with user's session), and applications that know how to recover from, or do not care about lost connections.
Migrating processes with their external network connections is WIP.
In both cases, there needs to be some userspace glue to ensure that the same filesystem view is available on the target machine as was on the origin machine (e.g. remote file system, SAN, or even rsync of changes).
Also ,in both cases, we may want to pre-copy some of the application state while it is still running, to reduce the application downtime. This will be added down the road.
Oren.
Quoted 7 lines · Andrew Morton
Quoted 3 lines · On Wed, 23 Sep 2009 19:50:40 -0400 Oren Laadan <[email protected]> wrote:
Q: What about namespaces ?
A: Currrently, UTS and IPC namespaces are restored. They demonstrate
how namespaces are handled. More to come.Will this new code muck up the kernel?
Actually user namespaces are handled as well. Pid namespaces will be named and recorded by kernel at checkpoint, and re-created in userspace using clone(CLONE_NEWPID). This shouldn't muck up the kernel at all. The handling of network and mounts namespaces is at this point undecided. Well, mounts namespaces themselves are pretty simple, but not so much for mountpoints. There it's mainly a question of how to predict what a user wants to have automatically recreated. All mounts which differ between the root checkpoint task and its parent? Do we do no mounts for the restarted init task at all, and only recreate mounts in private child namespaces (i.e. if a task did a unshare(CLONE_NEWNS); mount --make-private /var; mount --bind /container2/var/run /var/run)?
I hear a decision was made at plumber's about how to begin handling them, so I'll let someone (Oren? Dave?) give that info.
For network namespaces i think it's clearer that a wrapper program should set up the network for the restarted init task, while the usrspace code should recreate any private network namespaces and veth's which were created by the application. But it still needs discussion.
Quoted 10 lines
Quoted 4 lines
Q: What additional work needs to be done to it?
A: Fill in the gory details following the examples so far. Current WIP
includes inet sockets, event-poll, and early work on inotify, mount namespace and mount-points, pseudo file systemsWill this new code muck up the kernel, or will it be clean?
Quoted 1 line
and
x86_64support.eh? You mean the code doesn't work on
x86_64at present?
There have been patches for it, but I think the main problem is noone involved has hw to test.
Quoted 2 lines
What is the story on migration? Moving the process(es) to a different machine?
Since that's basically checkpoint; recreate container on remote machine; restart on remote machine; that will mainly be done by userspace code exploiting the c/r kernel patches.
The main thing we may want to add is a way to initiate pre-dump of large amounts of VM while the container is still running. I suspect Oren and Dave can say a lot more about that than I can right now.
thanks,
-serge
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 11 lines · Serge E. Hallyn
Quoted 9 lines · Andrew Morton
Quoted 4 lines · On Wed, 23 Sep 2009 19:50:40 -0400 Oren Laadan <[email protected]> wrote:
Q: What about namespaces ?
A: Currrently, UTS and IPC namespaces are restored. They demonstrate
how namespaces are handled. More to come.Will this new code muck up the kernel?
[ cut ]
Quoted 6 lines
For network namespaces i think it's clearer that a wrapper program should set up the network for the restarted init task, while the usrspace code should recreate any private network namespaces and veth's which were created by the application. But it still needs discussion.
Ok for the restart, but for the checkpoint, how do you access the network setup from a process which belongs to another namespace context ?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
DL> Ok for the restart, but for the checkpoint, how do you access the DL> network setup from a process which belongs to another namespace DL> context ?
So far the discussion has led to the kernel dumping all of that information on checkpoint, and then splitting it up into what can be done by userspace on restart and what still needs to be in the kernel.
Similarly, the task structure is currently exported by the kernel on checkpoint, but recreated in userspace on restart.
Signature · 9 lines
Dan Smith IBM Linux Technology Center email: [email protected] -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 8 lines · Dan Smith
DL> Ok for the restart, but for the checkpoint, how do you access the DL> network setup from a process which belongs to another namespace DL> context ?
So far the discussion has led to the kernel dumping all of that information on checkpoint, and then splitting it up into what can be done by userspace on restart and what still needs to be in the kernel.
Ah, this was a discussion in the containers@ mailing list ? Sorry I missed it, I will look at the containers@ archives.
If the checkpoint is done from the kernel, why the restart wouldn't be in the kernel too ? Do you have a list of what is restartable from userspace or from the kernel ?
Is there any documentation about the statefile format I can use if I want to implement myself an userspace CR solution based on this kernel patchset ?
Quoted 3 lines
Similarly, the task structure is currently exported by the kernel on checkpoint, but recreated in userspace on restart.
(I guess you meant tasks hierarchy/tree) Well I understand why this is done from userspace but I don't like the idea of digging in the statefile, but there's no accounting for taste :)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
DL> If the checkpoint is done from the kernel, why the restart DL> wouldn't be in the kernel too ?
I think thus far we have taken the approach of "if it can be done reasonably in userspace, then do it there" right? Setup of the network devices is easy to do in userspace, allows more flexibility from a policy standpoint, and ensures that all existing security checks are performed. Also, migration may be easier if the userspace bits can call custom hooks allowing for routing changes and other infrastructure-specific operations.
DL> Is there any documentation about the statefile format I can use if DL> I want to implement myself an userspace CR solution based on this DL> kernel patchset ?
See linux-cr/include/linux/checkpoint_hdr.h and user-cr/restart.c.
Signature · 9 lines
Dan Smith IBM Linux Technology Center email: [email protected] -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 5 lines · Dan Smith
DL> If the checkpoint is done from the kernel, why the restart DL> wouldn't be in the kernel too ?
I think thus far we have taken the approach of "if it can be done reasonably in userspace, then do it there" right?
Well I am a little lost :)
The tty CR can be "reasonably" done in userspace I think. But it was done in the kernel, no ?
Quoted 4 lines
Setup of the
network devices is easy to do in userspace, allows more flexibility from a policy standpoint, and ensures that all existing security checks are performed.
Yep, I agree. But you didn't answer the question, what are the network resources you plan to checkpoint / restart ? eg. you let the container to setup your network, will you restore netdev statistics ? the mac address ? ipv4 ? ipv6 ?
Is it possible to do a detailed list of network resources you plan to CR with the different items you will address from userspace and kernel space ?
Quoted 4 lines
Also, migration may be easier if the userspace
bits can call custom hooks allowing for routing changes and other infrastructure-specific operations.
You may have some problems with the connected sockets you will restore in this case.
Quoted 6 lines
DL> Is there any documentation about the statefile format I can use if DL> I want to implement myself an userspace CR solution based on this DL> kernel patchset ?
See
linux-cr/include/linux/checkpoint_hdr.handuser-cr/restart.c.
Argh ! I was hoping there was something else than the source code :)
Thanks
-- Daniel
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
DL> Yep, I agree. But you didn't answer the question, what are the DL> network resources you plan to checkpoint / restart ? eg. you let DL> the container to setup your network, will you restore netdev DL> statistics ? the mac address ? ipv4 ? ipv6 ?
Yes, Yes, Yes, and Yes. I'm making the assumption that the common case will be with a veth device in the container and that all of the aforementioned attributes should be copied over. In the future case where we could potentially have a real device in the container, it probably doesn't make sense to copy the mac address.
DL> Is it possible to do a detailed list of network resources you plan DL> to CR with the different items you will address from userspace and DL> kernel space ?
I'm sure it's possible, but no, I haven't planned out everything for the next year. If you have strong feelings about what should be done in user and kernel space, feel free to share :)
DL> Argh ! I was hoping there was something else than the source code
The header file makes it pretty clear what is going on, but maybe the Documentation/checkpoint/readme.txt will help. Putting all the details in such a documentation file would be rather silly at the moment, given that new things are being added at a rapid rate and it would duplicate the only description that matters, which is the header file.
Signature · 9 lines
Dan Smith IBM Linux Technology Center email: [email protected] -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 11 lines · Dan Smith
DL> Yep, I agree. But you didn't answer the question, what are the DL> network resources you plan to checkpoint / restart ? eg. you let DL> the container to setup your network, will you restore netdev DL> statistics ? the mac address ? ipv4 ? ipv6 ?
Yes, Yes, Yes, and Yes. I'm making the assumption that the common case will be with a veth device in the container and that all of the aforementioned attributes should be copied over. In the future case where we could potentially have a real device in the container, it probably doesn't make sense to copy the mac address.
Be careful with the assumptions ;)
Quoted 8 lines
DL> Is it possible to do a detailed list of network resources you plan DL> to CR with the different items you will address from userspace and DL> kernel space ?
I'm sure it's possible, but no, I haven't planned out everything for the next year. If you have strong feelings about what should be done in user and kernel space, feel free to share :)
Dan,
I just want to understand what is your plan. If you say "yes I will checkpoint / restart" ipv4, ipv6, netdev statistics, etc ... you should be able to give at least a small list of network resources you will checkpoint and how you will restart them, no ?
Quoted 3 lines
DL> Argh ! I was hoping there was something else than the source code
The header file makes it pretty clear what is going on,
Certainly for you.
We are a little far away of the sys_checkpoint / sys_restart simple syscalls we talked about at the cr-minisummit in 2008.
Regards,
-- Daniel
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 7 lines · Daniel Lezcano
Quoted 3 lines · Dan Smith
DL> Argh ! I was hoping there was something else than the source code
The header file makes it pretty clear what is going on,
Certainly for you.
We are a little far away of thesys_checkpoint/sys_restartsimple syscalls we talked about at the cr-minisummit in 2008.
Yes. We did those, and were asked to provide a fuller implementation. Here is what we have so far... We're open, in fact eager, to see other people's implementations based on different designs, but here is what *we*'ve got.
Oh, and it was NEVER said at the cr-minisummit that we would have simple syscalls doing a full, complicated c/r. Only that we would start with simple syscalls to do a single task with no open resources. And you can still do that with v18, with one simple syscall.
-serge
Quoted 3 lines · Daniel Lezcano
Quoted 1 line · Dan Smith
The header file makes it pretty clear what is going on,
Certainly for you.
If you're worried about hooking lxc-restart up and that being a mess, i have said that as soon as something hits -mm, I will hook up lxc-restart. I do agree, the userspace code would be much simpler if we didn't need to do all of the process tree creation in userspace :) I *would* prefer if we didn't have to parse the image in userspace. But the moment it was decided that portability across kernel versions woudl be done by having userspace process the image, we lost that fight.
-serge
A message that is not in the archive (sent off-list or not yet received): 20090930224249.GA22977-r/[email protected]
Quoted 11 lines · Serge E. Hallyn
Quoted 6 lines · Daniel Lezcano
Quoted 2 lines · Dan Smith
The header file makes it pretty clear what is going on,
Certainly for you.
If you're worried about hooking lxc-restart up and that being a mess,
Yep, I am worried about that too :)
Quoted 4 lines
i have said that as soon as something hits -mm,
I will hook up lxc-restart. I do agree, the userspace code would be much simpler if we didn't need to do all of the process tree creation in userspace :)
Yes and I know there were discussions about this point several times for the proctree, I won't argue with kernel vs user proctree creation. But what I understood is you will continue to parse the statefile to recreate some other resources like a subset of the network and here I am lost.
Who in the linux community will understand what is checkpointed and what is restored from the kernel or from the userspace ?
Does this imply someone has to use a specific tool like "restart.c" within its own tools, assuming this tool is installed in the system or shall he copy-paste the code of the GPL licensed restart.c to its LGPL licensed tools ?
I am not arguing against the Checkpoint / Restart, IMO the general approach is good.
But I am just worried about who will be able to implement a CR solution using what is provided by the kernel, except a few people who implemented it.
Quoted 6 lines
I *would* prefer if
we didn't have to parse the image in userspace. But the moment it was decided that portability across kernel versions woudl be done by having userspace process the image, we lost that fight.
Yeah, a big deal.
Thanks
-- Daniel
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 17 lines · Daniel Lezcano
Quoted 10 lines · Serge E. Hallyn
Quoted 5 lines · Daniel Lezcano
Quoted 1 line · Dan Smith
The header file makes it pretty clear what is going on,
Certainly for you.
If you're worried about hooking lxc-restart up and that being a mess,
Yep, I am worried about that too :)
Quoted 4 lines
i have said that as soon as something hits -mm,
I will hook up lxc-restart. I do agree, the userspace code would be much simpler if we didn't need to do all of the process tree creation in userspace :)
Quoted 5 lines
Yes and I know there were discussions about this point several times for the proctree, I won't argue with kernel vs user proctree creation. But what I understood is you will continue to parse the statefile to recreate some other resources like a subset of the network and here I am lost.
If network devices end up being recreated in userspace - either the ones for the root restarted container, or all the devices including for any child network namespaces - then I believe they will be considered container objects. All the container information is at the top of the checkpoint file, so the program coordinating the restart will see all of the information before the task hierarchy. Actually, I thought linux-2.6/Documentation/checkpoint/readme.txt used to explicitly show a 'container information' section between the image header and task hierarchy. Oren?
Quoted 2 lines
Who in the linux community will understand what is checkpointed and what is restored from the kernel or from the userspace ?
It should all be documented linux-2.6/Documentation/checkpoint/. But right now it's not even settled whether process creation in userspace is going to be the final acceptable way, so documenting speculation about how we're going to do network devices just seems too certain to not end up matching reality.
Quoted 4 lines
Does this imply someone has to use a specific tool like "
restart.c" within its own tools, assuming this tool is installed in the system or shall he copy-paste the code of the GPL licensedrestart.cto its LGPL licensed tools ?
Hmm, I think a tiny little lgpl library, maybe even shipping under the kernel tree, implementing a generic, whole-container and sub-tree checkpoint and restart, makes very good sense.
It certainly does NOT make sense to require multiple projects to track all changes to the checkpoint image format as the kernel changes...
-serge
A message that is not in the archive (sent off-list or not yet received): 20091001145512.GA17916-r/[email protected]
Quoted 23 lines · Serge E. Hallyn
Quoted 16 lines · Daniel Lezcano
Quoted 9 lines · Serge E. Hallyn
Quoted 5 lines · Daniel Lezcano
Quoted 1 line · Dan Smith
The header file makes it pretty clear what is going on,
Certainly for you.
If you're worried about hooking lxc-restart up and that being a mess,
Yep, I am worried about that too :)
Quoted 4 lines
i have said that as soon as something hits -mm,
I will hook up lxc-restart. I do agree, the userspace code would be much simpler if we didn't need to do all of the process tree creation in userspace :)Quoted 5 lines
Yes and I know there were discussions about this point several times for the proctree, I won't argue with kernel vs user proctree creation. But what I understood is you will continue to parse the statefile to recreate some other resources like a subset of the network and here I am lost.
Quoted 9 lines
If network devices end up being recreated in userspace - either the ones for the root restarted container, or all the devices including for any child network namespaces - then I believe they will be considered container objects. All the container information is at the top of the checkpoint file, so the program coordinating the restart will see all of the information before the task hierarchy. Actually, I thought
linux-2.6/Documentation/checkpoint/readme.txtused to explicitly show a 'container information' section between the image header and task hierarchy. Oren?
It used to. I'll put it back there, now that somebody cares :)
But yes, the idea is that the part in which userspace is involved is at the beginning of the image file, to avoid kernel-userspace bouncing.
Quoted 3 lines
Quoted 3 lines
Who in the linux community will understand what is checkpointed and what is restored from the kernel or from the userspace ?
Interested developers, and they can look at the code and read the documentation. Assuming suitable tools are available for the users, who else would care ?
Quoted 6 lines
It should all be documented linux-2.6/Documentation/checkpoint/. But right now it's not even settled whether process creation in userspace is going to be the final acceptable way, so documenting speculation about how we're going to do network devices just seems too certain to not end up matching reality.
Here is my view on the subject (I'll add it to the documentation).
* By design, we do everything in the kernel, unless there is a strong reasoning to move something to userspace.
* Keep a clear distinction for what we move to userspace. Avoid doing something partly in kernel and partly in userspace.
* Streamline logic, so the execution flow doesn't bounce in and out of the kernel. What's done in userspace appears _first_ in the image file.
* My rules of thumb to take something to userspace are:
1. If it can be done _easily_ and _uniformly_ in userspace, _and_
2. If doing it in userspace gives us _substantial_ flexibility, or coverage, or portability that is difficult in the kernel.
Let me demonstrate this thinking with 3 examples: open files (in kernel), tasks tree (userspace), and network namespaces (userspace).
Why not restore open files in userspace ? because some file types are hard to do in userspace, and we want uniform handling. Also, it becomes very tricky to do in userspace in the presence of mount points, chroots, and mount namespaces.
Why restore the tasks tree in userspace ? because it's easy and portable (using the new clone); because it is unrelated to where/how we do other resource; because it gives the flexibility for the restarting tasks to do useful things after they are created but before they call sys_restart (flexibility).
Why restore network namespace (their setup) in userspace ? because it's easy and portable, and network setup tools are well developed and understood; because we will want some policy to it (e.g. restart doesn't care which actual device is used, we don't want such decision to be in the kernel); because we don't want to replicate the rich high level tools from userspace inside the kernel; because you may want to change the configuration compare to checkpoint (e.g. add firewall).
(That said, this is not written in stone, and if you have strong arguments to convince otherwise, this is a good time).
Quoted 6 lines
Quoted 5 lines
Does this imply someone has to use a specific tool like "
restart.c" within its own tools, assuming this tool is installed in the system or shall he copy-paste the code of the GPL licensedrestart.cto its LGPL licensed tools ?
Quoted 7 lines
Hmm, I think a tiny little lgpl library, maybe even shipping under the kernel tree, implementing a generic, whole-container and sub-tree checkpoint and restart, makes very good sense.
It certainly does NOT make sense to require multiple projects to track all changes to the checkpoint image format as the kernel changes...
The idea is to add a plugin architecture to restart to allow users to execute any useful work before and after the tasks tree is created, but prior to calling sys_restart().
And yes, eventually making this a library, too.
Oren.
A message that is not in the archive (sent off-list or not yet received): 877hvgnv6z.fsf-FLMGYpZoEPULwtHQx/[email protected]
Quoted 11 lines · Dan Smith
DL> Yep, I agree. But you didn't answer the question, what are the DL> network resources you plan to checkpoint / restart ? eg. you let DL> the container to setup your network, will you restore netdev DL> statistics ? the mac address ? ipv4 ? ipv6 ?
Yes, Yes, Yes, and Yes. I'm making the assumption that the common case will be with a veth device in the container and that all of the aforementioned attributes should be copied over. In the future case where we could potentially have a real device in the container, it probably doesn't make sense to copy the mac address.
Be careful with the assumptions ;)
Quoted 8 lines
DL> Is it possible to do a detailed list of network resources you plan DL> to CR with the different items you will address from userspace and DL> kernel space ?
I'm sure it's possible, but no, I haven't planned out everything for the next year. If you have strong feelings about what should be done in user and kernel space, feel free to share :)
Dan,
I just want to understand what is your plan. If you say "yes I will checkpoint / restart" ipv4, ipv6, netdev statistics, etc ... you should be able to give at least a small list of network resources you will checkpoint and how you will restart them, no ?
Quoted 3 lines
DL> Argh ! I was hoping there was something else than the source code
The header file makes it pretty clear what is going on,
Certainly for you.
We are a little far away of the sys_checkpoint / sys_restart simple syscalls we talked about at the cr-minisummit in 2008.
Regards,
-- Daniel
A message that is not in the archive (sent off-list or not yet received): [email protected]
DL> Yep, I agree. But you didn't answer the question, what are the DL> network resources you plan to checkpoint / restart ? eg. you let DL> the container to setup your network, will you restore netdev DL> statistics ? the mac address ? ipv4 ? ipv6 ?
Yes, Yes, Yes, and Yes. I'm making the assumption that the common case will be with a veth device in the container and that all of the aforementioned attributes should be copied over. In the future case where we could potentially have a real device in the container, it probably doesn't make sense to copy the mac address.
DL> Is it possible to do a detailed list of network resources you plan DL> to CR with the different items you will address from userspace and DL> kernel space ?
I'm sure it's possible, but no, I haven't planned out everything for the next year. If you have strong feelings about what should be done in user and kernel space, feel free to share :)
DL> Argh ! I was hoping there was something else than the source code
The header file makes it pretty clear what is going on, but maybe the Documentation/checkpoint/readme.txt will help. Putting all the details in such a documentation file would be rather silly at the moment, given that new things are being added at a rapid rate and it would duplicate the only description that matters, which is the header file.
Signature · 3 lines
Dan Smith IBM Linux Technology Center email: danms-r/[email protected]
A message that is not in the archive (sent off-list or not yet received): 87eipoo0po.fsf-FLMGYpZoEPULwtHQx/[email protected]
Quoted 5 lines · Dan Smith
DL> If the checkpoint is done from the kernel, why the restart DL> wouldn't be in the kernel too ?
I think thus far we have taken the approach of "if it can be done reasonably in userspace, then do it there" right?
Well I am a little lost :)
The tty CR can be "reasonably" done in userspace I think. But it was done in the kernel, no ?
Quoted 4 lines
Setup of the
network devices is easy to do in userspace, allows more flexibility from a policy standpoint, and ensures that all existing security checks are performed.
Yep, I agree. But you didn't answer the question, what are the network resources you plan to checkpoint / restart ?
eg. you let the container to setup your network, will you restore netdev statistics ? the mac address ? ipv4 ? ipv6 ?
Is it possible to do a detailed list of network resources you plan to CR with the different items you will address from userspace and kernel space ?
Quoted 4 lines
Also, migration may be easier if the userspace
bits can call custom hooks allowing for routing changes and other infrastructure-specific operations.
You may have some problems with the connected sockets you will restore in this case.
Quoted 6 lines
DL> Is there any documentation about the statefile format I can use if DL> I want to implement myself an userspace CR solution based on this DL> kernel patchset ?
See
linux-cr/include/linux/checkpoint_hdr.handuser-cr/restart.c.
Argh ! I was hoping there was something else than the source code :)
Thanks
-- Daniel
A message that is not in the archive (sent off-list or not yet received): [email protected]
DL> If the checkpoint is done from the kernel, why the restart DL> wouldn't be in the kernel too ?
I think thus far we have taken the approach of "if it can be done reasonably in userspace, then do it there" right? Setup of the network devices is easy to do in userspace, allows more flexibility from a policy standpoint, and ensures that all existing security checks are performed. Also, migration may be easier if the userspace bits can call custom hooks allowing for routing changes and other infrastructure-specific operations.
DL> Is there any documentation about the statefile format I can use if DL> I want to implement myself an userspace CR solution based on this DL> kernel patchset ?
See linux-cr/include/linux/checkpoint_hdr.h and user-cr/restart.c.
Signature · 3 lines
Dan Smith IBM Linux Technology Center email: danms-r/[email protected]
A message that is not in the archive (sent off-list or not yet received): 87iqf0o5sf.fsf-FLMGYpZoEPULwtHQx/[email protected]
Quoted 8 lines · Dan Smith
DL> Ok for the restart, but for the checkpoint, how do you access the DL> network setup from a process which belongs to another namespace DL> context ?
So far the discussion has led to the kernel dumping all of that information on checkpoint, and then splitting it up into what can be done by userspace on restart and what still needs to be in the kernel.
Ah, this was a discussion in the containers@ mailing list ? Sorry I missed it, I will look at the containers@ archives.
If the checkpoint is done from the kernel, why the restart wouldn't be in the kernel too ?
Do you have a list of what is restartable from userspace or from the kernel ?
Is there any documentation about the statefile format I can use if I want to implement myself an userspace CR solution based on this kernel patchset ?
Quoted 3 lines
Similarly, the task structure is currently exported by the kernel on checkpoint, but recreated in userspace on restart.
(I guess you meant tasks hierarchy/tree) Well I understand why this is done from userspace but I don't like the idea of digging in the statefile, but there's no accounting for taste :)
A message that is not in the archive (sent off-list or not yet received): [email protected]
DL> Ok for the restart, but for the checkpoint, how do you access the DL> network setup from a process which belongs to another namespace DL> context ?
So far the discussion has led to the kernel dumping all of that information on checkpoint, and then splitting it up into what can be done by userspace on restart and what still needs to be in the kernel.
Similarly, the task structure is currently exported by the kernel on checkpoint, but recreated in userspace on restart.
Signature · 3 lines
Dan Smith IBM Linux Technology Center email: danms-r/[email protected]
A message that is not in the archive (sent off-list or not yet received): 20090928163704.GA3327-r/[email protected]
Quoted 11 lines · Serge E. Hallyn
Quoted 9 lines · Andrew Morton
Quoted 4 lines · On Wed, 23 Sep 2009 19:50:40 -0400 Oren Laadan…
Q: What about namespaces ?
A: Currrently, UTS and IPC namespaces are restored. They demonstrate
how namespaces are handled. More to come.Will this new code muck up the kernel?
[ cut ]
Quoted 6 lines
For network namespaces i think it's clearer that a wrapper program should set up the network for the restarted init task, while the usrspace code should recreate any private network namespaces and veth's which were created by the application. But it still needs discussion.
Ok for the restart, but for the checkpoint, how do you access the network setup from a process which belongs to another namespace context ?
Hi,
Quoted 22 lines · Andrew Morton
Quoted 8 lines · On Wed, 23 Sep 2009 19:50:40 -0400 Oren Laadan <[email protected]> wrote:
Q: How useful is this code as it stands in real-world usage?
A: The application can be single- or multi-processes and threads. It
handles open files (regular files/directories on most file systems, pipes, fifos,af_unixsockets,/dev/{null,zero,random,urandom}and pseudo-terminals. It supports shared memory. sysv IPC (except undo of sempahores). It's suitable for many types of batch jobs as well as some interactive jobs. (Note: it is assumed that the fs view is available at restart).That's encouraging.
Quoted 7 lines
Q: What can it checkpoint and restart ?
A: A (single threaded) process can checkpoint itself, aka "self"
checkpoint, if it calls the new system calls. Otherise, for an "external" checkpoint, the caller must first freeze the target processes. One can either checkpoint an entire container (and we make best effort to ensure that the result is self-contained), or merely a subtree of a process hierarchy.
Quoted 2 lines
What is "best effort"? Will the operation appear to have succeeded, only it didn't?
There are two modes of operation: a "full" (container) checkpoint and a "subtree" checkpoint.
For container-checkpoint, the application runa within its own set of namespaces (pid, uts, ipc ...). We have a leak-detection algorithm in place to ensure that the application is entirely contained and isolated in the container, or else the checkpoint fails. In this case, restart is guaranteed to succeed (assuming external dependencies are properly set - see below).
A "subtree" checkpoint is less restrictive. It allows to checkpoint applications that aren't truly isolated. In this case, restart may fail, or restart may succeed but the application may fail shortly after because some dependency may be missing. However, in practice this works well for many applications transparently, and even more so for c/r-aware application.
In both modes of operation, some external dependencies are assumed to exist. One example is the file system view that has to be the same for the container (or subtree) as during checkpoint. Another is the network setup. These will be reconstructed (at least in part) by userspace prior to the actual restart.
(Some of these dependencies can be relaxed for many use-cases, e.g. when user/application doesn't care about preserving original network connection after restart).
Quoted 2 lines
IOW, how reliable and robust is code at detecting that it was unable to successfully generate a restartable image?
To the best of my knowledge (and unless someone pokes a hole in the algorithm), container-checkpoint is robust and reliable.
Two reasons for saying "best effort": first, because external dependencies need to be suitably arranged. If external dependencies are not arranged - e.g. provide a snapshot of the filesystem from the time of the checkpoint - restart, or execution thereafter, may fail.
Second, because even when the application is isolated within a container, the user from outside may still be able to affect it. I can think of one (and only one) pathological example: an outside process signals all tasks in a container during a checkpoint, but the signal is recorded for only some tasks. I'd argue that this is improper behavior that we need not support, rather than address it in the kernel.
Quoted 6 lines
Quoted 4 lines
Q: What about namespaces ?
A: Currrently, UTS and IPC namespaces are restored. They demonstrate
how namespaces are handled. More to come.Will this new code muck up the kernel?
I forgot to mention user-ns is already included. We have a good plan for mount-ns and mount-points, and intend to handle net-ns in userspace (by that, I mean the net-ns setup, not the state of connections etc).
I don't expect this additional code to be less solid than the current one.
Quoted 7 lines
Quoted 5 lines
Q: What additional work needs to be done to it?
A: Fill in the gory details following the examples so far. Current WIP
includes inet sockets, event-poll, and early work on inotify, mount namespace and mount-points, pseudo file systemsWill this new code muck up the kernel, or will it be clean?
Should not.
I guess "gory details" was a bad choice of words, and I really meant to say "less interesting". IOW, I think we have constructed a solid and framework. From the kernel side, I think we're left with completeness - add support for remaining missing features (e.g. inotify), and goodies - live migration and other optimizations.
Quoted 9 lines
Quoted 2 lines
and
x86_64support.eh? You mean the code doesn't work on
x86_64at present?What is the story on migration? Moving the process(es) to a different machine?
It depends on the use-case in mind:
Moving processes between machines without preserving external network connections (or IP), already works. This can be useful for servers (e.g. apache, or vnc with user's session), and applications that know how to recover from, or do not care about lost connections.
Migrating processes with their external network connections is WIP.
In both cases, there needs to be some userspace glue to ensure that the same filesystem view is available on the target machine as was on the origin machine (e.g. remote file system, SAN, or even rsync of changes).
Also ,in both cases, we may want to pre-copy some of the application state while it is still running, to reduce the application downtime. This will be added down the road.
Oren.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>